PASO 7: ¡Ahora vamos a crear un número aleatorio para elegir un índice aleatorio de la lista principal!
Ir a y arrastre Random Integer al final de su programa (¡en la segunda sección!). Cambie el nombre de la variable de my_var a random_head . Cambie el rango en .randint() a 0 , 5 . Recuerde: hay 6 elementos en la lista, por lo que el primer índice es 0 y el último índice es 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!
Enviar Trabajo
Actividad Siguiente
Stop Running Code
Show Chart
Show Console
Reset Code Editor
Codesters How To (opens in a new tab)