0

if statement doubt

num = 7 if num > 3: print("3") if num < 5: print("5") if num ==7: print("7") in q&a part this one ur answer is 3 but 7 also will come na

29th Jul 2020, 1:54 PM
Udhay Shankar.D
Udhay Shankar.D - avatar
2 Answers
+ 2
num > 3 returns true print("3") num < 5 returns false if num == 7 is not executed because this if statement belongs to if num < 5 So the output should be only 3
29th Jul 2020, 2:01 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
The first 'if' statement is true, so primarily the output will be 3. But the second 'if' statement is false, hence all the statement under this second statement is false and will not be operated. So the final output will be only 3
29th Jul 2020, 4:02 PM
1AmN0t0k@eArth