+ 1
How would you get this to output correctly?
num = 10 if num < 5: print("Number is less than 5") if num > 5: print("Number is greater than 5") print("Proceed") Im new to this but im trying to challenge myself. ive tried but cant seem to figure out how to print out both "Number is greater than 5" and afterwards if the statement is correct "Proceed" but if i add the last part of the code thats the only part that outputs if i remove it, the output is no output
4 Answers
+ 17
Indentation matters in Python!
Remove the whitespaces before "if num>5:"
This indentation implies that, if the number is less than 5, only then the 2nd condition will be checked.
+ 18
My pleasure đ Since unlike other languages, we can't separate the body of if/for/else/while using curly braces {}, indentation is the only way to handle that. So wrong indentation can change the whole game đ And thanks for choosing my answer as best đ
+ 2
Omg thank you so much it works!
+ 2
Yea i see now, i just didnt really understand the indention thing i was unaware that i had to unindent the next if statement inorder for it to check the 2nd if, due to the previous lesson that had the 2 if statements nested. but that clears it up for me tho i feel more comfortable fs, no problem thank you for helping!