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"]
def space_bar():
my_var = random.choice(my_list)
sprite.set_color(my_var)
# add other actions...
stage.event_key("space", space_bar)
t = codesters.Teacher()
event = t.find_block('def')
asks = t.get_parameters_for_function('ask')
ask_text = t.find_function('ask')
print(asks)
try:
tval1a = int(event[5][0])
tval1b = t.get_indent_at_line(event[5][0])
tval1c = event[5][1]
except:
tval1a = -1
tval1b = -1
tval1c = "DNE"
try:
tval2a = int(ask_text[0][0])
tval2b = t.get_indent_at_line(tval2a)
tval2c = ask_text[0][1].replace(" ", "")
except:
tval2a = -1
tval2b = -1
tval2c = "DNE"
t1 = TestObjective()
t1.add_success('a_key' in tval1c and tval1b == 0, "Great job!")
t1.add_failure(tval1c == "DNE", "Did you drag My Key Press into your program?")
t1.add_failure('a_key' not in tval1c, "Did you drag My Event Key into your program?")
t1.add_failure(tval1b > 0, "Make sure your event definition is not indented.")
t2 = TestObjective()
t2.add_success('width=' in tval2c and 'int(' in tval2c and tval2b == 4, "Great job!")
t2.add_failure(tval2c == "DNE", "Did you drag Ask for Integer into your event?")
t2.add_failure('int(' not in tval2c, "Did you add the correct Ask command?")
t2.add_failure(tval2a < tval1a, "Did you add your Ask for Integer command inside your Key Press event?")
t2.add_failure('width=' not in tval2c, "Did you change the name of the user input variable to width?")
t2.add_failure(tval2b > 4, "It looks like you indented too far. Make sure your Ask for Integer command is only 4 spaces in.")
t2.add_failure(tval2b < 4, "Make sure your Ask for Integer command is indented 4 spaces in your event block.")
tester = TestManager()
tester.add_test_list([t1, t2])
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)