Isn’t the last example of the if-statements supposed to show two values? | Sololearn: Learn to code for FREE!

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

4/13/2021 4:13:01 AM

Madeirak

3 Answers

New Answer

+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

+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")

0

I understand. Thank you very much John Doe and CarrieForle