Why it is showing "invalid syntax" or "indentation error"? | Sololearn: Learn to code for FREE!

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

7/24/2021 12:52:40 PM

not_a_programmer

10 Answers

New Answer

+4

#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

+3

because you didn't indent the statement after if and else condition

+3

I got It.. worked.. Thank u šŸ‘šŸ»

+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

+1

Not yet, now it's showing "invalid syntax" error at else :