+ 1
What is my syntax error?
In the following code, what is my syntax error? try: name = input() #your code goes here if (len(name) < 4): raise NameError("error") except: print("Invalid Name")
8 Answers
+ 2
I only remove 1 character before "if" and it worked (I did not change anything else)?
(edited)
https://code.sololearn.com/cfRRMN31oa8h/?ref=app
+ 5
Check the indentation of the if-statement: There's one blank space too many.
+ 3
Hi Mohammad Reza Morawej !
You have to fix the indentation:
Your if statment should be a part if the try statement, because it is between the try statement and the except statment. So put if at the same level as the other lines that are inside the try statement (like name = input()).
âŠ
âŠ
try:
âŠ
âŠ
if ⊠:
raise âŠ
except:
âŠ
âŠ
âŠ
+ 2
Mohammad Reza Morawej
The issue is not "Tab instead of spaces", there is just a space too many in front of "if" â it needs to be the same indentation level as "name".
Please read the answers you get before marking your own comment as "best"
+ 2
Per Bratthammar Thanks! đ
I adjusted my previous comment. I just wanted to make sure that it becomes evident, that it is not an issue of tab vs. space per se but of correct alignment of lines (as it appeared on sl)
+ 1
We must place Tab instead of four spaces.
+ 1
Dear Lisa ,
I have checked what you said before I mark my answer as best. It did not help. Modified code as per you said works well in other compilers such as in visual studio. But, it still gives a syntax error in solo learn. Tab key solves the problem.
Thank you again
+ 1
(Hi, Lisa !
I think it can be a bit confusing. It was a newline character you removed, not a space.)