0

I am trying to create a game from a book by Eric Matthes and I am getting a error for some reason I am getting the syntax error before this it was a indenation error. Let me know if you guys can help me in this, thanks.

import sys
import pygame
def check_events(ship):
    """Respond to keypresses and mouse events."""
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_RIGHT:
                # Move the ship to the right.
GSerg
  • 76,472
  • 17
  • 159
  • 346
Haadi
  • 1
  • Please refer to the following answer: https://stackoverflow.com/questions/43189302/syntaxerror-unexpected-eof-while-parsing – Moustapha Ramadan Jul 20 '21 at 22:25
  • 2
    If you want to stub out the suite associated with an `if` statement, you can use `pass`. The comment itself won't be a good placeholder for a suite. – Ben Y Jul 20 '21 at 22:27
  • `if` statements must have at least one line of actual code indented underneath. Your last `if` statement does not have this. – John Gordon Jul 20 '21 at 22:42

1 Answers1

2

I ran your code, the only error I got was with the comment on the last line. therefore, it looks like the comment inside the "if" statement is the problem. To solve it, I replaced this with something else (I just used "pass" for testing) and that worked. Hope this helps!

import sys
import pygame

def check_events(ship):
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_RIGHT:
                pass
Reisu
  • 25
  • 8
  • 1
    The comment inside the `if` statement is most likely the cause of the problem. You could add an explanation to that effect so that the OP and future users understand better. – Code-Apprentice Jul 20 '21 at 22:29