I am trying out some stuff in python using the pygame module. this is my code:
import pygame, sys
direction = " "
pygame.init()
try:
while True:
for events in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygaqme.KEYDOWN:
if event.key == pygame.K_w:
forward = True
elif event.key == pygame.K_a:
left = True
elif event.key == pygame.K_s:
reverse = True
elif event.key == pygame.K_d:
right = True
elif event.type == pygame.KEYUP:
if event.key == pygame.K_w:
forward = False
elif event.key == pygame.K_a:
left = False
elif event.key == pygame.K_s:
reverse = False
elif event.key == pygame.K_d:
right = False
if forward:
print ("forward")
elif left:
print("left")
elif reverse:
print("reverse")
elif right:
print("right")
And on executing this, python tells me that line 35 has invalid syntax, but the problem is that my code is only 34 lines long. I checked to see if there was an accidental new line created and it turns out there was. So I deleted that and executed it again but I still got the same error.
trystatement (used to catch an exception) and not finished it anexcept, which would appear on line 35 at the latest. Is thetrynecessary here? If so, add anexcept; otherwise, you can remove it.),], or}on the previous line, or (2) you've got atry:without anyexcept:/finally:farther up the current block. (And if it's not one of those, the next thing to look for is mixing tabs and spaces and hiding problem (1) or (2).)