WARNING: This program has a bug, which means we need to fix it! This bug is a logic error .
RULE: The handler listens for the signal to run the event. It should not be indented.
Click Run and wait 1 second. Watch the stage to see what's wrong with the program. A snowflake should appear and start to fall every half-second, but they aren't. Unindent the event handler on line 15 so that the snow starts to fall!
To navigate the page using the TAB key, first press ESC to exit the code editor.
stage.set_background("winter2")
tint = codesters.Square(0, 0, 500, "black")
tint.set_opacity(0.5)
stage.disable_floor()
def interval():
x = random.randint(-250, 250)
snowflake = codesters.Sprite("snowflake1", x, 350)
snowflake.set_size(random.randint(3, 7)/10)
snowflake.set_y_speed(random.randint(-5, -1))
# add any other actions...
stage.event_interval(interval, .5)
t = codesters.Teacher()
handler = t.find_function('event_interval')
try:
tval1 = t.get_indent_at_line(handler[0][0])
except:
tval1 = "DNE"
t1 = TestObjective()
t1.add_success(tval1 == 0, "Great job debugging the program!")
t1.add_failure(tval1 == "DNE", "Oops! Did you delete the event handler?")
t1.add_failure(tval1 != 0 and tval1 != "DNE", "Make sure the handler is not indented in your event block.")
tester = TestManager()
tester.add_test_list([t1])
tester.run_tests()
tester.display_first_feedback()
Run Code
Activity Submitted!
Submit Work
Next Activity
Stop Running Code
Show Chart
Show Console
Reset Code Editor
Codesters How To (opens in a new tab)