Skip to main content

6.3.5 Cmu Cs Academy -

# Arrow key logic if key == 'up': if circle.centerY - speed >= 20: # Keep within top edge circle.centerY -= speed elif key == 'down': if circle.centerY + speed <= 380: # Keep within bottom edge circle.centerY += speed elif key == 'left': if circle.centerX - speed >= 20: # Keep within left edge circle.centerX -= speed elif key == 'right': if circle.centerX + speed <= 380: # Keep within right edge circle.centerX += speed

def onKeyPress(key): global circle # Movement speed speed = 15

# 6.3.5 - Moving Circle with Arrow Keys # CMU CS Academy Solution circle = None 6.3.5 Cmu Cs Academy

def onKeyRelease(key): global moveLeft if key == 'left': moveLeft = False

In the CMU CS Academy curriculum—specifically within the (Introduction to Programming) or CS1 courses—Unit 6 is dedicated to "Events and Interactions." Section 3 focuses on keyboard input, and exercise 6.3.5 is where the rubber meets the road. # Arrow key logic if key == 'up': if circle

Happy coding, and may your keypresses always be detected! This article is part of a series on CMU CS Academy exercise solutions. For help with 6.3.6, 6.4.1, or the final project, check out the related guides.

# Hold-to-move (smooth) moveLeft = False def onKeyPress(key): global moveLeft if key == 'left': moveLeft = True For help with 6

def onKeyPress(key): circle.centerX += 15 # Error: circle is not defined