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")
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.
+ 1
@Denise RoĂberg thanks!