STEP 8: Green is nice, but what if the user wants a different color? Let's add a way to change the pen's color.
We'll create a list of colors. A list is a way to store multiple values at once.
Click the LOGIC tab in the toolkit, then click . Drag out Rainbow and drop it at the very bottom of your program.
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)
t = codesters.Teacher()
expected_list = ["red", "orange", "yellow", "green", "blue", "indigo", "violet"]
try:
tval1 = set(my_list)
except:
tval1 = "DNE"
# try:
# tval2 = my_list
# except:
# tval2 = "DNE"
t1 = TestObjective()
t1.add_success(tval1 == set(expected_list), "Great Job!")
# t1.add_failure(tval2 != "DNE", "Did you change the list's name from my_list to colors?")
t1.add_failure(tval1 == "DNE", "Did you add a rainbow list?")
t1.add_failure(tval1 != set(expected_list), "Did you add the correct list?")
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)