stage.set_background_color("black")
# sprite = codesters.Point(x, y)
sprite = codesters.Point(50, 100)
sprite.set_color("green")
sprite.pen_down()
def right_key():
sprite.move_right(20)
# add other actions...
stage.event_key("right", right_key)
t = codesters.Teacher()
func = t.find_block('def')
moves = t.find_function('move_left')
call = t.find_function('event_key')
try:
tval1 = func[1][1]
tval2 = t.get_indent_at_line(func[1][0])
except:
tval1 = "DNE"
tval2 = "DNE"
try:
tval3 = moves[0][1]
tval4 = t.get_indent_at_line(moves[0][0])
except:
tval3 = "DNE"
tval4 = "DNE"
try:
tval5 = call[1][1]
tval6 = t.get_indent_at_line(call[1][0])
except:
tval5 = "DNE"
tval6 = "DNE"
t1 = TestObjective()
t1.add_success('left_key' in tval1 and tval2 == 0, "Great job!")
t1.add_failure(tval1 == "DNE", "Did you add a left key event?")
t1.add_failure('left_key' not in tval1, "Did you add a left key event?")
t1.add_failure(tval2 > 0, "Oops! Make sure your up key event is outside of your other key event and not indented!")
t2 = TestObjective()
t2.add_success('sprite.move_left(' in tval3 and tval4 == 4, "Great job!")
t2.add_failure(tval3 == "DNE", "Oops! Did you delete the .move_left() command from your left key event?")
t2.add_failure(tval4 < 4, "Oops! Did you unindent your .move_left()?")
t2.add_failure(tval4 > 4, "Make sure the command inside your event is indented only 4 spaces.")
t3 = TestObjective()
t3.add_success('stage.event_key("left"' in tval5 and tval6 == 0, "Great job!")
t3.add_failure(tval5 == "DNE", "Oops! Did you delete your event handler?")
t3.add_failure('stage.event_key("left"' not in tval5, "Oops! Did you change the event handler?")
t3.add_failure(tval6 > 0, "Make sure your event handler is outside the event and not indented at all!")
tester = TestManager()
tester.add_test_list([t1, t2, t3])
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)