6.3.5 Cmu Cs Academy -

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.

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. 6.3.5 Cmu Cs Academy

Unlike text-based problems on LeetCode or Codecademy, CMU CS Academy asks you to build shapes, animate objects, and respond to user input (mouse clicks and keyboard presses) within a 400x400 canvas. Unit 6 changes everything. In earlier units, code runs top-to-bottom and stops. In Unit 6, you write event handlers —functions that sit dormant until a specific action occurs. Happy coding, and may your keypresses always be detected

def onKeyRelease(key): global moveLeft if key == 'left': moveLeft = False In the CMU CS Academy curriculum—specifically within the

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

# 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