6.3.5 Cmu Cs Academy (UHD 360p)

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:

def onKeyRelease(key): global moveLeft if key == 'left': moveLeft = False 6.3.5 Cmu Cs Academy

def onStep(): if moveLeft: circle.centerX -= 5 The boundary check uses 20 and 380 because the radius is 20

def onKeyPress(key): global circle # Movement speed speed = 15 Here is why: Mistake #1: Forgetting global Every

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

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)

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:

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

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

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

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

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)