if statements | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

if statements

Last one question in this part, why in explanation before output is 2 print, mean "Bigger than 5 Between 5 and 47", but when num = 7 if num > 3: print("3") if num < 5: print("5") if num ==7: print("7") output is 3, not 37 ?

1st Mar 2020, 5:18 PM
Alex
Alex - avatar
3 Answers
+ 1
It's because the "if num == 7:" is within the scope of the "if num < 5:" Since "if num < 5:" is false it cant check "if num ==7" Simply do num = 7 if num > 3: print("3") if num<5: print("5") if num == 7: print("7") #The if num < 5 and if num == 7 should be indented the same amount, it should line up the two if statements
1st Mar 2020, 5:26 PM
Odyel
Odyel - avatar
0
oh i just took a deeper look and i can explain why its 37 its bigger than 3 and equal 7. 5 doesnt print cuz its not less than 5
1st Mar 2020, 5:27 PM
Florian Vanik
Florian Vanik - avatar
0
Saved me time!
25th Jun 2020, 1:26 AM
Ali Akhtar
Ali Akhtar - avatar