[Tutor] Indentation Frustrations

Mark Lawrence breamoreboy at gmail.com
Wed Nov 18 19:25:52 EST 2020


On 18/11/2020 22:19, Nathaniel Dodson wrote:
> Please, for the love of God, why am I constantly getting indentation errors
> when I'm trying to write some simple Pygame code? I have Googled the error
> messages and it says my indentation has to be uniform. But it is for Pete's
> sake! I'm ripping my hair out bc I'm not copying and pasting the code; I'm
> typing it line for line from a tutorial. I get to a certain point and it
> just gives me indentation error after indentation error. This is the code,
> and when I get to the part to assign keyboard key functions for movement,
> it gives me "expected an indented block" error (and always highlights the
> "i" in the if statement in red):
> 
> import pygame
> pygame.init()
> 
> win = pygame.display.set_mode((500, 500))
> pygame.display.set_caption("First Game")
> 
> x = 50
> y = 50
> width = 40
> height = 60
> vel = 5
> 
> run = True
> 
> while run:
>      pygame.time.delay(100)
> 
>      for event in pygame.event.get():
>          if event.type == pygame.QUIT:
>              run = False
> 
>      keys = pygame.key.get_pressed()
> 
>      if keys[pygame.K_LEFT]:

Looks as if there's some code missing here.

>      if keys[pygame.K_RIGHT]:

Hence the above line will give an indentation error.
Just carry on down 
https://www.techwithtim.net/tutorials/game-development-with-python/pygame-tutorial/pygame-tutorial-movement/ 
and you'll find what's missing :)

> 
> I'm not getting what's going on. I know about mixing tabs with spaces, and
> I'm not doing that. That's what I learned through Googling the issue.
> 

My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence



More information about the Tutor mailing list