STEP 7: Now let's create a random number to pick a random index from the head list!
Go to and drag Random Integer to the bottom of your program (in the second section!).
Change the variable name from my_var to random_head .
Change the range in .randint() to 0, 5 .
Remember: there are 6 items in the list, so the first index is 0 and the last index is 5.
To navigate the page using the TAB key, first press ESC to exit the code editor.
########################################################################
# PLACE LIST CREATIONS HERE #
########################################################################
stage_list = ["moon", "mars", "jupiter", "pluto", "space", "city"]
head_list = ["head1", "head2", "head3", "head4", "head5", "head6"]
########################################################################
# PLACE ALL OTHER CODE BELOW THIS #
########################################################################
stage_image = stage_list[1]
stage.set_background(stage_image)
t = codesters.Teacher()
comments = t.find_text('ALL OTHER', True)
heads = t.find_text('random_head')
try:
tval0 = int(comments[0][0])
except:
tval0 = 0.0
try:
ranges = t.get_parameters_for_function('randint')
tval1 = int(ranges[0][0])
tval2 = int(ranges[0][1])
except:
tval1 = "DNE"
tval2 = "DNE"
try:
tval3 = random_head
except:
tval3 = "DNE"
try:
tval4 = int(heads[0][0])
except:
tval4 = 0.0
t1 = TestObjective()
t1.add_success(tval1 == 0 and tval2 == 5 and tval3 != "DNE" and tval0 < tval4, "Great job!")
t1.add_failure(tval1 == "DNE", "Did you add a Random Integer?")
t1.add_failure(tval1 == 1 or tval2 == 10, "Did you change the range in .randint() to 0,5?")
t1.add_failure(tval3 == "DNE", "Did you rename the random variable random_head?")
t1.add_failure(tval0 > tval4, "Oops! Make sure this line of code is in the bottom section of the program!")
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)