6.3.5 Cmu Cs Academy -
Even smart students fail 6.3.5 on the first try. Here is why:
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.
You might wonder, "When will I ever need nested loops for a 2D grid?" The answer is: constantly. The pattern you learn in 6.3.5 is the foundation for: 6.3.5 Cmu Cs Academy
Mastering this small exercise prepares you to write more complex programs, such as Conway’s Game of Life, a tic-tac-toe AI, or a maze generator.
While 6.3.5 uses "step" movement (move 15px per key press), later exercises (like 6.3.7 or 6.4.2) introduce continuous movement using onKeyHold. Once you master 6.3.5, you can upgrade to: Even smart students fail 6
# Hold-to-move (smooth) moveLeft = Falsedef onKeyPress(key): global moveLeft if key == 'left': moveLeft = True
def onKeyRelease(key): global moveLeft if key == 'left': moveLeft = False Mastering this small exercise prepares you to write
def onStep(): if moveLeft: circle.centerX -= 5
But for 6.3.5, stick to the discrete movement inside onKeyPress.
Error: Placing the grid.append(current_row) inside the inner loop instead of the outer loop.
Result: A grid where each row has only one element.
Fix: Ensure grid.append(current_row) is aligned with the for r loop, not the for c loop.