gpt4 book ai didi

python - 为什么 else 条件不适用于 Python If-else 语句?

转载 作者:太空宇宙 更新时间:2023-11-04 00:52:55 24 4
gpt4 key购买 nike

<分区>

代码:

#Loop to conduct program. User input required for each option. 

count = 1
while count == 1:
score = input("Enter Test Score: ")
if (score >= 90) and (score <= 100):
print "A"
elif (score >= 80) and (score <= 89):
print "B"
elif (score >= 70) and (score <= 79):
print "C"
elif (score >= 60) and (score <= 69):
print "D"
elif (score <= 59):
print "F"
elif (score == quit):
print "Program Finsihed. Goodbye."
count = 0 #Count to end loop
else:
print "Please enter valid response."

所有其他条件都有效,但是,如果键入的内容不符合参数,代码应该再次提示它们(这就是 while 循环的用途)。但是,每当尝试使用与参数不匹配的字符串时,就会出现错误。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com