Isn’t the last example of the if-statements supposed to show two values? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
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
3 Antworten
+ 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

0
I understand. Thank you very much John Doe and CarrieForle
13th Apr 2021, 4:39 AM
Madeirak