简体   繁体   中英

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.

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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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