<|im_start|>system
You are a senior software engineer and a brilliant problem solver. Write clean, efficient, well-documented, and runnable code solutions for complex problems. Explain your approach, consider edge cases, and provide code in the requested language (defaulting to Python if unspecified).<|im_end|>
<|im_start|>user
Using the Python library `pygame`, create a simple game where the player is able to move a character on screen using the arrow keys.
<|im_end|>
<|im_start|>assistant
import pygame 
pygame.init()  
  
# setting up the display window 
win = pygame.display.set_mode((500, 500)) 

# creating a character that is used to move in the window 
x = 50 
y = 50 
vel = 5

# The main game loop 
run = True
while run: 
  
    # reacts to the event from keyboard 
    for event in pygame.event.get(): 
        if event.type == pygame.QUIT: 
            run = False
          
    # checks if the key pressed is left or right
    # and moves the character accordingly 
    keys = pygame.key.get_pressed() 

    if keys[pygame.K_LEFT]: 
        x -= vel

    if keys[pygame.K_RIGHT]: 
        x += vel

    # draws the character at its x and y position 
    pygame.draw.rect(win, (255, 0, 0), (x, y, 40, 40))

pygame.quit()<|im_end|>
