0

Why does this code show no output

num = 6 if num == 5: print("Bigger than 5") if num <=47: print("Between 5 and 47")

16th Apr 2019, 4:06 AM
Ryan Myers
Ryan Myers - avatar
7 odpowiedzi
+ 5
The first condition is False, so the whole block below it (including the second "if condition") is not executed.
16th Apr 2019, 4:30 AM
Diego
Diego - avatar
+ 1
I changed it to an elif so that the code would run even after a condition was no met and it works now thanks for helping me work through that much appreciated
16th Apr 2019, 4:37 AM
Ryan Myers
Ryan Myers - avatar
0
You have given wrong indentation. Second block of if statement is indented wrong. It will be outside of first if block
16th Apr 2019, 4:16 AM
Mayur Kashyap
Mayur Kashyap - avatar
0
Could it be that == is not a valid function for solely if statements and bi should run this as an 'elif' statement instead?
16th Apr 2019, 4:22 AM
Ryan Myers
Ryan Myers - avatar
0
== is valid. I have checked it only problem is of indentation.
16th Apr 2019, 4:24 AM
Mayur Kashyap
Mayur Kashyap - avatar
0
Are you checking in this apps playground or in actual python?
16th Apr 2019, 4:25 AM
Ryan Myers
Ryan Myers - avatar
0
Apps playground
16th Apr 2019, 4:26 AM
Mayur Kashyap
Mayur Kashyap - avatar