+ 1
if statement
What is the output of this code? num = 7 if num > 3: print("3") if num < 5: print("5") if num ==7: print("7") sir, why the answer wont be 7?
11 Respuestas
+ 7
Because 7 is not less than 5. So it will not go inside nested if part
+ 4
Because the number isn't smaller than 5 only the first if statement will be executed.
The output will be 3.
+ 4
I guess what you wanted to do is:
num = 7
if num > 3:
print(3)
if num < 5:
print(5)
if num == 7:
print(7)
+ 3
This exact question was asked a week ago.
Read through this post for the answer in full
https://www.sololearn.com/Discuss/2232416/?ref=app
+ 3
it's matter of blocks
if num >3: # True
print("3") # 3 printed
if num < 5: # False
print("5")
# here python go out of this block and don't excute any thing inside this block
# notice that if num == 7 is inside the False block.
that mean python will not print 5 and will not verify if num == 7
finally don't print 7
+ 1
Because of the indentation, the code stop running after completing the first query.
if num >3: #True
print('3') #3
If you were to remove the indentation, then the code will examine each query for a result of 3
7
+ 1
Thank you everyone for your clarification
+ 1
This question is similar PRIYANKA K.
It won't print 7 because the second statement is false therefore leaving the third statement void.
0
the third if statement actullary has == not ==. so it will be if num === 7. I think
0
as num=7, so num<5 won't hold and only the first segment of the code will be executed.