Why this is only output 3 and not 7 as well for nested if-statements? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why this is only output 3 and not 7 as well for nested if-statements?

I am sorry if someone has asked this, but I could not find it. This is from one of the knowledge check questions on if-statements. Since num == 7 is True, why does this code only have 3 as an output. num = 7 if num > 3: print("3") if num < 5: print("5") if num == 7: print("7")

17th Apr 2019, 8:26 PM
Jaron H-M
Jaron H-M - avatar
2 Answers
+ 3
num = 7 if num > 3: print("3") if num < 5: print("5") if num == 7: print("7") This code will print 3 & 7 I think in your code the statement if num == 7 belongs to the statement if num < 5. So it will not be checked.
17th Apr 2019, 9:03 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
@Denise Roßberg thanks!
13th Jan 2020, 2:15 PM
Ricky
Ricky - avatar