0

why is this thing happens ?

What is the output of this code? num = 7 if num > 3: print("3") if num < 5: print("5") if num ==7: print("7") it says the ans is 3 but in the last line it says if num ==7: print("7") num = 7 the ans should be 7 then why it says 3

9th Aug 2019, 4:49 PM
Ayan Sinha
Ayan Sinha - avatar
3 Answers
+ 4
Hi In up code it first check the condition num > 3 which is ture . That's why it print 3. If tne statement num==7 is written brfore this statement it prints 7. This is the reason. Hope this will help you😊
9th Aug 2019, 5:22 PM
Muaz Ahmad
Muaz Ahmad - avatar
+ 3
num is not < 5, so from that line onwards the code is not executed.
9th Aug 2019, 4:52 PM
HonFu
HonFu - avatar
+ 1
7 < 5 is False so the code below this if never gets executed.
9th Aug 2019, 4:51 PM
unChabon
unChabon - avatar