0

Why it is showing "invalid syntax" or "indentation error"?

x=1 while x<10: if x%2==0: print(str(x) + "is even") else: print(str(x) +"is odd") x+=1

24th Jul 2021, 12:52 PM
Amrit Sahni
Amrit Sahni - avatar
10 Answers
+ 5
#Why it is showing "invalid syntax" or "indentation error"? x=1 while x<10: if x%2==0: print(str(x) + "is even") else: print(str(x) +"is odd") x+=1 Your indentation is wrong try with this code, it's a way to learn how this works
25th Jul 2021, 10:53 PM
John Logan Balcazar Ampuero
John Logan Balcazar Ampuero - avatar
+ 4
I got It.. worked.. Thank u đŸ‘đŸ»
24th Jul 2021, 1:42 PM
Amrit Sahni
Amrit Sahni - avatar
+ 3
because you didn't indent the statement after if and else condition
24th Jul 2021, 12:54 PM
Rellot's screwdriver
Rellot's screwdriver - avatar
+ 2
It should be like this from if. if x%2==0: print(str(x)+"is even") else: print(str(x)+"is odd") ...
24th Jul 2021, 12:56 PM
Lelouch Vi Britannia
Lelouch Vi Britannia - avatar
+ 2
x += 1 There should be a space between variable name and operator
24th Jul 2021, 1:04 PM
Lelouch Vi Britannia
Lelouch Vi Britannia - avatar
+ 2
#try this x=1 while x<10: if x%2==0: print(str(x) + "is even") else: print(str(x) +"is odd") x+=1
24th Jul 2021, 1:35 PM
Simba
Simba - avatar
+ 1
I did it on my computer but it still showing the error
24th Jul 2021, 1:02 PM
Amrit Sahni
Amrit Sahni - avatar
+ 1
Ohh thank u so much 😊
24th Jul 2021, 1:05 PM
Amrit Sahni
Amrit Sahni - avatar
+ 1
Did it work?
24th Jul 2021, 1:07 PM
Lelouch Vi Britannia
Lelouch Vi Britannia - avatar
+ 1
Not yet, now it's showing "invalid syntax" error at else :
24th Jul 2021, 1:19 PM
Amrit Sahni
Amrit Sahni - avatar