+ 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")

9th Jul 2022, 8:02 PM
Mohammad Reza Moravejolahkami
Mohammad Reza Moravejolahkami - avatar
8 odpowiedzi
+ 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
10th Jul 2022, 7:02 AM
Lisa
Lisa - avatar
+ 5
Check the indentation of the if-statement: There's one blank space too many.
9th Jul 2022, 8:06 PM
Lisa
Lisa - avatar
+ 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: … … …
10th Jul 2022, 6:35 AM
Per Bratthammar
Per Bratthammar - avatar
+ 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"
10th Jul 2022, 6:49 AM
Lisa
Lisa - avatar
+ 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)
10th Jul 2022, 8:03 AM
Lisa
Lisa - avatar
+ 1
We must place Tab instead of four spaces.
10th Jul 2022, 5:47 AM
Mohammad Reza Moravejolahkami
Mohammad Reza Moravejolahkami - avatar
+ 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
10th Jul 2022, 6:54 AM
Mohammad Reza Moravejolahkami
Mohammad Reza Moravejolahkami - avatar
+ 1
(Hi, Lisa ! I think it can be a bit confusing. It was a newline character you removed, not a space.)
10th Jul 2022, 8:00 AM
Per Bratthammar
Per Bratthammar - avatar