It is beceause python executes a codes by moving line to line. So when it reaches the first condition which verifies.... Then it excecutes.
Plus also the indentation is causing the problem to the execution of the code.
If it is removed it will output both 3&7
First of all change all if statements to "elif" except the first one and plz correct the indentation of the if statements..
num = 7
if num > 3:
elif num < 5:
elif num == 7:
This Output Is 7.
U need to understand how indentation works in python. It's similar to curly brackets in c and java
Edit : please ignore the best answer, it was marked best by the guy who asked the question who is clearly learning the ropes.
if statement can be used as many times as required. it is not necessary to use elif or else after an if statement
In If condition first condition 7>3
So it enters in if statement. Now the main trick comes- second if condition comes in first if statement and third if condition comes under second if statement. Because second if condition 7<5 is wrong so it doesn't enters in second if statement, this way the third if condition is never applied to be checked. Replace all 7 with 4 will see desired effect
As the condition is in 3rd if which is nested inside an if statement (num < 5) which will result false so the code written inside it (included third if condition) will not be read by compiler so it will not get executed.