简体   繁体   English

我不知道为什么我的 'elif' 和 'else' 代码不起作用

[英]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')

It works when I type 95 to 100, but it doesn't work when I type other numbers.它在我输入 95 到 100 时有效,但在我输入其他数字时无效。

Use ints to compare numbers, not strings:使用整数来比较数字,而不是字符串:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM