In the line that reads: def·a_key():, change the event name to w_key().
In the event handler, change the first argument to "w" .
Change the second argument in the event handler to w_key.
To navigate the page using the TAB key, first press ESC to exit the code editor.
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)
def a_key():
pass # delete after adding indented code
width = int(sprite.ask("Enter a number from 1 to 10."))
sprite.pen_width(width)
# add other actions...
stage.event_key("a", a_key)
t = codesters.Teacher()
try:
event_key = t.find_block('def')
tval1 = event_key[5][1]
tval1a = t.get_indent_at_line(event_key[5][0])
line1 = event_key[5][0]
except:
tval1 = "DNE"
tval1a = "DNE"
line1 = "DNE"
t1 = TestObjective()
t1.add_success('w_key' in tval1 and tval1a == 0, "Great job!")
t1.add_failure(tval1 == "DNE", "Did you drag in a My Key Press event?")
t1.add_failure(tval1a != 0, "Make sure you don't indent the event definition!")
t1.add_failure('w_key' not in tval1, "Did you change the name of your key press event?")
try:
event = t.find_text('event')
tval7 = event[5][1]
tval8 = t.get_indent_at_line(event[5][0])
line6 = event[5][0]
except:
tval7 = "DNE"
tval8 = "DNE"
line6 = "DNE"
t6 = TestObjective()
t6.add_success('stage.event_key("w", w_key)' in tval7 and tval8 == 0, "Great job!")
t6.add_failure(tval7 == "DNE", "Oops! Did you delete your event handler?")
t6.add_failure(tval8 > 0, "Oops! Did you indent your event handler?")
t6.add_failure('"w"' not in tval7, 'Did you change the first parameter in the handler to "w"?')
t6.add_failure('w_key' not in tval7, 'Did you change the second parameter in the handler to w_key?')
tester = TestManager()
tester.add_test_list([t1, t6])
tester.run_tests()
tester.display_first_feedback()
Are you already running a Codesters project in another tab or window?
Micro:bit can only connect to one web page at a time.
Try stopping other Codesters projects or closing
other tabs or windows that may be using your Micro:bit.
If that doesn't fix the problem try disconnecting your Micro:bit,
reloading this page, and reconnecting your Micro:bit.