如何同时使用 OR 条件和 '<='和'>='函数在一行中

发布于 2025-01-17 15:28:07 字数 633 浏览 1 评论 0 原文

这里的初学者。我已经发布了所有代码,但我相信该错误包含在底部的两条特定代码行中,以粗体。显然,我的语法是错误的,但我不明白如何。我已经尝试在括号中重新指定数字和/或将或条件的每一侧都放置,但没有任何作用。我屏幕上的错误标记/指针似乎放置在大于/小的符号下。即使我简化了删除或条件,它也会引发错误。

final_score = str(digit_one) + str(digit_two)
print(f"So the two digit score is {(int(final_score))}")

# 3of3 Final Outputs
**if final_score (<= 10) or (>= 90):**

    print(f"Your score is {final_score}, you go together like coke and mentos.")

**if final_score >= 40 and <= 50:**

    print(f"Your score is {final_score}, you are alright together.")

else:

    print(f"Your score is {final_score}.")

Beginner here. I've posted all code but I believe the error is contained to the two specific lines of code at the bottom in bold. Clearly my syntax is wrong but I can't understand how; I've tried re-specifying INT for numbers and/or putting each side of the OR condition in parentheses, but nothing works. The error marker/pointer on my screen seems to be placed under the greater than/less than symbols. It also throws an error even if I simplify to remove the OR condition.

final_score = str(digit_one) + str(digit_two)
print(f"So the two digit score is {(int(final_score))}")

# 3of3 Final Outputs
**if final_score (<= 10) or (>= 90):**

    print(f"Your score is {final_score}, you go together like coke and mentos.")

**if final_score >= 40 and <= 50:**

    print(f"Your score is {final_score}, you are alright together.")

else:

    print(f"Your score is {final_score}.")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

好菇凉咱不稀罕他 2025-01-24 15:28:07

您只需在每个条件之前重复该变量即可。此外,Python语法不需要括号。试试这个:

if final_score <= 10 or final_score >= 90:
  print(f"Your score is {final_score}, you go together like coke and mentos.")
if final_score >= 40 and final_score <= 50:
  print(f"Your score is {final_score}, you are alright together.")
else:
  print(f"Your score is {final_score}.")

You just have to repeat the variable before each condition. Besides, python syntax does not requires parentheses. Try this:

if final_score <= 10 or final_score >= 90:
  print(f"Your score is {final_score}, you go together like coke and mentos.")
if final_score >= 40 and final_score <= 50:
  print(f"Your score is {final_score}, you are alright together.")
else:
  print(f"Your score is {final_score}.")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文