0

Isn’t the last example of the if-statements supposed to show two values?

Example: num = 7 if num > 3: print (β€œ3”) if num < 5: print (β€œ5”) if num == 7: print (β€œ7”) β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” Output: 3 7

13th Apr 2021, 4:13 AM
Madeirak
Madeirak - avatar
3 Answers
+ 5
I assume this is python (please tag the language. There are others...) num > 3 is true so 3 is printed. num 5 is false so that block will not be executed. Thus only 3 is printed. Note that num==7 is nested within the num<5 block, thus it will not be executed
13th Apr 2021, 4:25 AM
John Doe
+ 2
num == 7 is inside of num < 5. num < 5 is false and therefore it won't do anything inside of itself. You get output 37 if you do this: num = 7 if num > 3: print("3") if num < 5: print("5") if num == 7: print("7")
13th Apr 2021, 4:25 AM
CarrieForle
CarrieForle - avatar
0
I understand. Thank you very much [user id=5443234]John Doe[/user] and [user id=13253423]CarrieForle[/user]
13th Apr 2021, 4:39 AM
Madeirak
Madeirak - avatar