+ 1

How do I know whether to indent my code in Python?

I have no clue. I also don't understand how num=7 if num > 3: print("3") if num ==7: print("7") is 3 and not 3 and 7. num (7) equal to 7, what gives?

4th Apr 2017, 4:06 PM
Abbie Ruperto
Abbie Ruperto - avatar
1 Resposta
+ 5
Indenting forms logical blocks of code. Everything inside the indented code of the loop will be executed by this loop, everything inside an if statement will be executed if the if is True. The above code will print "3" because num, which is equal to 7 is definitely more than 3. Then it will go inside the second block and will check if the same num is equal to 7. Since it is, it will print "7" in another line.
4th Apr 2017, 4:53 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar