6.3.5 Cmu Cs Academy May 2026

# 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 onKeyRelease(key): global moveLeft if key == 'left': moveLeft = False

The boundary check uses 20 and 380 because the radius is 20. The center of a 20px radius circle at x=20 touches the edge at x=0. Common Mistakes on 6.3.5 Even smart students fail 6.3.5 on the first try. Here is why: Mistake #1: Forgetting global Every time you modify circle inside onKeyPress , you must write global circle . If you forget, Python creates a local variable named circle , and the actual circle on screen never moves. Mistake #2: Using the Wrong Key Strings Many students try: 6.3.5 Cmu Cs Academy

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

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. # Arrow key logic if key == 'up': if circle

def onStep(): if moveLeft: circle.centerX -= 5

# Hold-to-move (smooth) moveLeft = False def onKeyPress(key): global moveLeft if key == 'left': moveLeft = True Here is why: Mistake #1: Forgetting global Every

If you are currently navigating the vibrant, graphics-driven world of CMU CS Academy , you have likely encountered the infamous checkpoint 6.3.5 . For many students, this specific exercise represents the first major leap from simple animation loops into the realm of interactive event handling.