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
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
+ 4
I got It.. worked.. Thank u đđ»
+ 3
because you didn't indent the statement after if and else condition
+ 2
It should be like this
from if.
if x%2==0:
print(str(x)+"is even")
else:
print(str(x)+"is odd")
...
+ 2
x += 1
There should be a space between variable name and operator
+ 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
+ 1
I did it on my computer but it still showing the error
+ 1
Ohh thank u so much đ
+ 1
Did it work?
+ 1
Not yet, now it's showing "invalid syntax" error at else :