0
Why is the output of this code also 5? Isn't the if num < 5: an inner statement of the if num> 3 ?
num = 7 if num > 3: print("3") if num < 5: print("5") if num ==7: print("7")
4 Answers
+ 6
The output is just 3.
if num > 3 returns true.
print 3
if num < 5 returns false
end of code
if you change it to if num > 5
Then it prints also 5 and executes the next if statement:
if num == 7 returns true
print 7
output:
3
5
7
+ 3
Esteban Rueda I think you are mistaken, the output is 3 only and Denise RoĂberg explained it nicely
Here is the code if you want to see:-
https://code.sololearn.com/cVbjv3YnnnQK/?ref=app
+ 2
Dejan Jovanovic let's go through the code line by line
num=7
If num>3: #true so it will go in
Print("3") #"3" printed
If num<5: #False
so it will not execute code within this "if" statement which includes rest of the code so interpreter will end the code.
+ 1
I still don't get it, why 3??? S.O.S.