【发布时间】:2023-03-08 05:25:01
【问题描述】:
无法理解我的代码有什么问题。无论student_status 的输入如何,它都会不断打印出additional_discount 值。 seen here is the code
def discount(x):
return x * .9
def additional_discount(x):
return discount(x) * .95
og_price = float(input("Please enter your current price in dolalrs: "))
student_status = str(input("Are you a student? "))
if student_status == "Yes" or "yes"
print("Your price is ", additional_discount(og_price))
elif student_status == "No" or "no":
print("Your price is ", discount(og_price))
else:
print("I'm sorry, that is an invalid response")
谢谢!
【问题讨论】:
-
Stackoverflow 鼓励包含代码而不是代码链接,以便其他人可以轻松进行实验。
-
您的问题是您错误地将一个值与多个值进行比较(即 student_status == "Yes" 或 "yes" 不正确)。如果 student_status == "YES" 或 student_status == "yes" 则使用。或者更简单地说:如果 student_status.lower() == "yes"
-
快速浏览了您的代码后,您只指定了 or 语句的一半 - “or ‘yes’’而不是 or x == ‘yes’。 Just or ‘yes’ 将始终评估为 true。
标签: python if-statement