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)
def left_key():
sprite.move_left(20)
# add other actions...
stage.event_key("left", left_key)
def up_key():
sprite.move_up(20)
# add other actions...
stage.event_key("up", up_key)
def down_key():
sprite.move_down(20)
# add other actions...
stage.event_key("down", down_key)
my_list = ["red", "orange", "yellow", "green", "blue", "indigo", "violet"]
t = codesters.Teacher()
key = t.find_block('def')
spaces = t.find_text('space_bar')
rands = t.get_parameters_for_function('choice')
rands_text = t.find_text('random.choice')
try:
tval1 = "DNE"
tval2 = "DNE"
for stored_var in key:
if "space_bar" in stored_var[1]:
tval1 = stored_var[1]
tval2 = t.get_indent_at_line(stored_var[0])
except:
tval1 = "DNE"
tval2 = "DNE"
try:
tval3 = rands[0][0]
tval4a = int(rands_text[0][0])
tval4b = t.get_indent_at_line(tval4a)
except:
tval3 = "DNE"
tval4a = 0
tval4b = -1
try:
tval5a = int(spaces[0][0])
tval5b = int(spaces[1][0])
except:
tval5a = -1
tval5b = -1
t1 = TestObjective()
t1.add_success('space_bar' in tval1 and tval2 == 0, "Great job!")
t1.add_failure(tval1 == "DNE", "Did you add a Space Bar event?")
t1.add_failure(tval2 > 0, "Make sure you don't indent the line that defines your event.")
t1.add_failure('space_bar' not in tval1, "Did you add a Space Bar event?")
t2 = TestObjective()
t2.add_success(tval3 == "my_list" and tval4b == 0, "Great job!")
t2.add_failure(tval3 == "DNE", "Did you add a Random Choice inside your event?")
t2.add_failure(tval4b > 4, "It looks like you indented your Random Choice command too far. Make sure it's 1 tab.")
t2.add_failure(tval4b < 4, "Make sure your Random Choice command is indented 1 tab.")
t3 = TestObjective()
t3.add_success(tval5a < tval4a < tval5b, "Great job!")
t3.add_failure((tval5a > tval4a) or (tval5b < tval4a), "Did you add Random Choice inside the Space Bar event?")
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)