Python IF condition | SoloLearn: Learn to code for FREE!


Python IF condition

What is the output of this code? num = 7 if num > 3: print("3") if num < 5: print("5") if num ==7: print("7") shouldn't that give 2 outputs? 3 and 7?

11/5/2019 3:29:04 PM


2 Answers

New Answer


No. Firstly it asks if num > 3 and it is true. Then it asks if num < 5, and it is false. Because the third if is inside the second if, it is not going to run. So, the only output is 3


The condition stops once the first "if - statement" is true. And why do you think, the output should be 2... I can't see print("2") ffom your code