+ 2
Wondering where the problem of my code is...
I am new on coding,and just started python. Just learned if and else statements. my code in question is... x = 7 if x == 7: if x > 4: if x < 2: print ("yes") else: print("no") since the third statement is false,Shouldnât it print ânoâ ? I do not get any output after running this code. however if i run it without the third statement,i get âYesâ
3 Answers
+ 1
Ahnaf Inan Your "else" block is only applicable for the first "if" statement here, and as it's True, the "else" block isn't executed. Try this code:
x = 7
if x == 7 and x > 4 and x < 2:
print("yes")
else:
print("no")
The result is always "no" as no number can be greater than 4 and less than 2, simultaneously.
+ 1
Calvin Thomas Thank you very much. I got it :)
0
Nikhil Thanks a lot for the explanation :D