+ 2

Please someone say why the code below prints all the 3 print's..while it should print the third print whichs "bye!" since 8==8

a=8 if a>8: print("yes") if a<9: print("yay") if a==8: print("bye!")

1st Dec 2018, 8:03 PM
RiGeL
RiGeL - avatar
1 Respuesta
+ 1
Unique Sharma, you should answer a question only if you know the answer, not just guess! Python doesn't need ;. RiGeL, nothing of this will be executed because a is not larger than 8! In Python, code blocks are separated by using indentation. You see that every line under the second is indented, so it all belongs to the first if.
1st Dec 2018, 8:41 PM
HonFu
HonFu - avatar