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")

11th Nov 2019, 1:44 PM
Esteban Rueda
Esteban Rueda - avatar
4 Respuestas
+ 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
11th Nov 2019, 2:21 PM
Denise Roßberg
Denise Roßberg - avatar
+ 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
11th Nov 2019, 4:25 PM
Arsenic
Arsenic - avatar
+ 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.
13th Nov 2019, 2:09 AM
Arsenic
Arsenic - avatar
+ 1
I still don't get it, why 3??? S.O.S.
13th Nov 2019, 2:04 AM
Dejan Jovanovic
Dejan Jovanovic - avatar