[英]I don't know why my 'elif ' and 'else' code does not work
score = input("What is your score? ")
if score == str(100):
print('Perfect!')
elif score <= str(range(95, 99)):
print('Great!')
elif score <= str(range(90, 95)):
print('Good')
else:
print('Fail')
它在我輸入 95 到 100 時有效,但在我輸入其他數字時無效。
使用整數來比較數字,而不是字符串:
score = int(input("What is your score? "))
if score == 100:
print('Perfect!')
elif score in range(95, 100): # This 100 catches the 99 case
print('Great!')
elif score in range(90, 95):
print('Good')
else:
print('Fail')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.