+ 1

x=5 y=8 if x==y: print ('c and y are equal') else : if x<y: print('x is less than y') else :

after if its showing invalid syntax to else why??

5th Jan 2017, 1:55 PM
ujawal kumar
ujawal kumar - avatar
3 Réponses
+ 6
If and else statements have to be on the same "level" Example: x=5 y=8 if x==y: print('x and y are equal') elif x<y: print('x is less than y') else: print('y is less than x')
5th Jan 2017, 2:04 PM
Anselm
+ 1
you can keep the same code to just move the if under else a bit right
5th Jan 2017, 3:39 PM
Sandeep Chatterjee
0
Python distinguishes the different "blocks of code" using indentation. This means that you should be very careful on how you write your code. Here the else statement should be placed exactly at the same level with the "if x==y" statement. In other words, these two statements should start from the same column.
5th Jan 2017, 2:15 PM
Miltiadis Siavvas