6.3.5 Cmu Cs Academy
One of the strengths of CMU CS Academy is that you can immediately visualize your grid. To test 6.3.5 within the CMU environment, you would add drawing code:
def draw_grid(app):
rows = 4
cols = 5
colors = alternating_colors(rows, cols)
cell_width = app.width / cols
cell_height = app.height / rows
for r in range(rows):
for c in range(cols):
fill = colors[r][c]
draw_rect(c * cell_width, r * cell_height,
cell_width, cell_height, fill=fill)
This allows you to see the checkerboard pattern instantly.
In previous units, you used app.step() to make things happen automatically. In Unit 6.3, you switch to Event-Driven programming. The code only runs when the user presses a key.
circle = None
def onAppStart(app): global circle # Create blue circle at center of 400x400 canvas circle = Circle(200, 200, 20, fill='blue') # Add it to the canvas add(circle)
def onKeyPress(key): global circle # Movement speed speed = 15
# 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
Note: 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.
The 6.3.5 CMU CS Academy exercise is a rite of passage in learning how to manipulate structured data. By mastering the alternating pattern using nested loops and the modulo operator, you have unlocked a transferable skill that applies to dozens of programming scenarios beyond the CMU environment.
Remember: the solution is not just about typing if (r+c)%2==0. It’s about understanding the relationship between row index, column index, and value. Once you internalize that, no grid-based problem will intimidate you. 6.3.5 Cmu Cs Academy
So go ahead—write your function, run the tests, and watch your checkerboard come to life in vibrant CMU Graphics colors. You’ve conquered 6.3.5. Now, on to the next challenge!
Happy coding, and remember: every expert programmer once struggled with nested loops. Persist, and you will master it.
To successfully complete 6.3.5, students must understand and apply the following concepts: One of the strengths of CMU CS Academy