0

help with if statement

num = 7 if num > 3: print("3") if num < 5: print("5") if num ==7: print("7") what is the output? why is it only 3 and not 3 and 7

28th Aug 2020, 8:33 AM
Samantha
2 Answers
0
num = 7 if num > 3: print("3") if num < 5: print("5") if num ==7: print("7")
28th Aug 2020, 9:50 AM
Samantha
0
Now num=7 The third condition statement Execute never. Because if num>5 the second condition not allow to check third condition Your third condition is inside of second if condition. The third condition will check, when second condition is become true. But it not give true forever. Even if num=7 not check third condition. Because second condition become false. Indentation is very important in Python.
28th Aug 2020, 9:55 AM
Vadivelan