+ 1

Python If statements

The first block of code doesn't work but the second works... why is this so? the image link : https://i.stack.imgur.com/UEsM8.png

25th Jul 2020, 6:46 AM
Adam Haller
Adam Haller - avatar
4 Respuestas
+ 3
First block: X=99 99<20(false)so it doesn't enter Second block: Num=12 12>5(true)so it enters
25th Jul 2020, 6:57 AM
v@msi😉
v@msi😉 - avatar
+ 2
It's because the condition in first block (x is less than 20 ) is not true, hence the statements in that block won't execute, whereas the condition in second block is true (num IS greater than 5), so the code statements in that block will be executed by the compiler.
25th Jul 2020, 6:55 AM
H-J
H-J - avatar
+ 1
but if executes the anyone of the if statements, it won't check the remaining statements. it will print the true statement.
25th Jul 2020, 8:45 AM
Mr. 12
Mr. 12 - avatar
0
Thank you very much, guys.... I was thinking the other way actually....
6th Aug 2020, 3:01 AM
Adam Haller
Adam Haller - avatar