lundi 29 mars 2021

Comparison of 3 values? in IF,ELIF

I have school assign about IF,ELIF(and new to this web).Actually its quiet simple,but im a bit confuse because this is my first time dealing with if,i found 3 ways to type the code,

score=int(input('Insert score : ')
if 100 >= score >= 81 :
    print('A')
elif 80 >= score >= 61 :
    print('B')
else : 
    print('C')
print()


----------
score=int(input('Insert score : ')
if 100 >= score and score >= 81 :
    print('A')
elif 80 >= score and score >= 61 :
    print('B')
else : 
    print('C')


----------
score=int(input('Insert score : ')
if 100 >= score :
    print('A')
elif 80 >= score:
    print('B')
else : 
    print('C')

Someone told me that the first one is wrong,Why is it wrong? And well the third one is more efficient,but i just dont know why the first one is wrong. Which code is better and i should use?

Aucun commentaire:

Enregistrer un commentaire