Home > Blockchain >  I get a indentation error when everything is properly indented. Why?
I get a indentation error when everything is properly indented. Why?

Time:11-23

I did write this code in pygame if that has something to do with it.

if x<=-50:
    x=-50

elif x>=1200:
    x=1200

Here's the error I got:

    Traceback (most recent call last):
  File "C:\Users\Dell\Desktop\Zombie survival\Gun_Boi_and_Zombie_Boi.py", line 3, in <module>
    from Main_Menu_Gun_Boi import mainmenu
  File "C:\Users\Dell\Desktop\Zombie survival\Main_Menu_Gun_Boi.py", line 91
    
    ^
IndentationError: expected an indented block

I haven't touched this piece of code in a while, and this just happened out of the blue. And the pointer doesn't help at all.

CodePudding user response:

Switch your IDE to use spaces instead of tabs. In VSCode's case go to the button that says Tabs: 4, click on it and select Spaces then select 4. This should fix your problem for the individual file but to permanently switch it to spaces: Open setting.json using command pallette --> add editor.insertSpaces: true.

CodePudding user response:

Happens to me also. I fix it by removing the indentation from every line and then manually adding it again.

CodePudding user response:

Double check that you consistently use either spaces or tabs. Mixing them will cause all kinds of trouble. You can enable your editor's option to show you whitespace caracters to help with keeping this consistency.

CodePudding user response:

Look at the top lines of your code at the import... No spaces should be in front of the word "from"

In the following line (the error code claims it is there even though you didn't post it...

Look to line 91 in method file... survival\Main_Menu_Gun_Boi.py

  • Related