This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by Dan
about 11 years

Possible issue (and solution) to many of the errors

I had error messages from the code I entered even though I could not find any problems either, as many of you have posted. I even ran it through the python interpreter and that worked fine, so I presumed it was this website. I was playing with indenting (because as well all know, whitespace is important! :) ) when I came upon the solution purely by accident… The answer? Spaces vs. Tabs!

If you are getting the error and you’re sure your code is good, try this (at least it worked for me):

  1. put your cursor at the beginning of a line that starts ‘elif’ or ‘else’ (it should be indented).
  2. hit the <backspace> key.
  3. if the cursor goes all the way to the beginning of the line, it was a <tab> character. replace it with 4 (four) spaces (i.e., hit <space bar> 4 times).

That should do it! Repeat for any ‘elif’ or ‘else’ lines you might have.

The caveat is, when you hit <backspace> in step 2, it only goes back one space instead of to the beginning of the line, there is another error and this solution won’t help you.

Hope this helps!

Answer 5100c851b58f038cb9001545

5 votes

Permalink

thank you so much!! I was working on this for a week trying to figure out what the hell was going on. I added spaces instead of using tab and it worked

points
about 11 years

2 comments

thewelshgreen about 11 years

language?

Guckenberger over 9 years

If I may Mr. Miguelgorry, I am very thankful as well. I am grateful for this gentleman’s aid.

Answer 510f42edf2d6782f5d0033bb

4 votes

Permalink

Thanks Dan. Yet I tried this and it’s still sending me error messages. : (

points
Submitted by Joeysuperbee
about 11 years

Answer 53f029ce52f86318f3000773

1 vote

Permalink

Thanks a lot! replacing the “tab” with 4 spaces worked for me

points
Submitted by Aseem Pathak
over 9 years

Answer 5463abca52f863fa060007ed

1 vote

Permalink

I’ve tried using both tab and for space and neither work. I’m still being told there is an indentation error.

points
Submitted by pattcodeson
over 9 years

1 comments

pattcodeson over 9 years

It eventually worked AFTER I erased the pre-written code and wrote it over again.

Answer 512c16fcfb0e1af186000029

0 votes

Permalink

Yeah, I’ve written and rewritten this code and still can’t make it work. I think the software needs reworking because it’s worked every time in PyLab.

points
Submitted by MMangan
about 11 years

Answer 52504c02548c358125009569

0 votes

Permalink

In addition to checking the spacing for me I had to make the last “return” line not indented/spaced at all. Also it requires that the colon be dropped (lol) at the end of the “else” line and added just after the “else:”

else: 1 == 1 and 2 == 2
return True
#obviously your other code would be above these lines
points
Submitted by Smitty
over 10 years

Answer 5388077b9c4e9d5c1e001ecd

0 votes

Permalink

File “python”, line 6 elif 70 - 4 == 3 : ^ SyntaxError: invalid syntax huh?

points
Submitted by Garrett Chavez
almost 10 years