Need help with pong game im a begginer


#1

I was told for my course that this was the code however I get this error

.
The code given is here, I’m new and I’m so lost :(.

import pygame #provides what we need to make a gameimport sys #gives us the sys.exit function to close our programimport random # can generate random positions for the pong ballfrom pygame.locals import*

pygame.init()

gameSurface = pygame.display.set_mode((450,450))# open a new window width = 440, height=480
pygame.display.set_caption(‘Gina Cooper’)# set the title of the window
pygame.mouse.set_visible(0)

GREEN=(0,200,0)
BLUE=(0,0,128)
PURPLE=(102,0,102)
WHITE=(255,255,255)

rect1x=20
rect1y=100
rect2x=400
rect2y=100#Draw the game surface, two rectangles. One at position 20, 100, 30 pixes wide and 150 tall#The other rectangle and 400, 100, with the same measurements
gameSurface.fill(WHITE)
pygame.draw.rect(gameSurface, GREEN,(rect1x, rect1y,30,150))
pygame.draw.rect(gameSurface, GREEN,(rect2x, rect2y,30,150))#put the ball on a random place on the screen
ballx=random.randint(200,300)
bally=random.randint(100,150)
pygame.draw.circle(gameSurface, BLUE,(ballx, bally),20)
pygame.display.update()

FPS=20
fpsClock=pygame.time.Clock()
pygame.key.set_repeat(1,1)#This will allow you to press and hold keys on the keyboard#game loopwhileTrue:foreventin pygame.event.get():
oldballx=ballx

    ifevent.type==KEYDOWN:#pressing q will quit the programifevent.key==K_q:
            pygame.quit()
            sys.exit()ifevent.key==K_RIGHT:#The right arrow key
            ballx=ballx+1#This moves the ball. Turn the old ball location white then create a new ball at the new location simulating movement
            pygame.draw.circle(gameSurface, WHITE,(oldballx, bally),20) 
            pygame.draw.circle(gameSurface, BLUE,(ballx, bally),20)elifevent.key==K_LEFT:#the left arrow key
            ballx=ballx-1
            pygame.draw.circle(gameSurface, WHITE,(oldballx, bally),20)
            pygame.draw.circle(gameSurface, BLUE,(ballx, bally),20)if ballx==70:
        pygame.draw.rect(gameSurface, PURPLE,(rect1x, rect1y,30,150))# If the ball reaches the rectangle turn it purpleif ballx==380:
        pygame.draw.rect(gameSurface,PURPLE,(rect2x, rect2y,30,150))#if the ball reaches the rectangle on the right side turn it purple
        

    pygame.display.update()       


fpsClock.tick(FPS)     

pygame.display.update()