dimanche 5 janvier 2020

2 if statement with 1 else destroying a loop

here my Python Code is

while True:
    a = int(input("enter a digit"))
    if a < 10:
        print("digit is less than 10")
    if a < 50 and a > 10:
        print("digit is more than 10")
    else:
        print("error")

so my doubt is when i run this program for (a < 10) then it will show the correct output with respected to it's if statement but it will also give the output of else statement as well with if. But with the if condition mentioned in second phrase which is (a<50 and a > 10), the output is only "digit is more than 10" which is correct but why there is an extra output of else,when value is less than 10 .

Aucun commentaire:

Enregistrer un commentaire