PREVIEW: We already know how to make a list and access every single item in that list using a loop.

But what if you only want to use just one item in the list? To do that you use an index.

  • Click Run and respond to the Ask prompt. Run the program again and try a different number.
  • Look at lines 19, 24, 29, and 34 in the code editor. These lines use indexes, which you will learn about today!
  • Click Submit and Next to start today's lesson!

######################################################################## # PLACE LIST CREATIONS HERE # ######################################################################## stage_list = ["summer", "underwater", "flowers", "mars", "subway","soccerfield"] head_list = ["head1", "head2", "head3", "head4", "head5", "head6"] body_list = ["middle1", "middle2", "middle3", "middle4", "middle5", "middle6"] legs_list = ["legs1", "legs2", "legs3", "legs4", "legs5", "legs6"] ######################################################################## # PLACE ALL OTHER CODE BELOW THIS # ######################################################################## head_image = head_list[3] display_which_head = codesters.Text(head_image, 100, 83) head = codesters.Sprite(head_image, 0, 83) rand_number = random.randint(0,5) body_image = body_list[rand_number] display_which_body = codesters.Text(body_image, 100, 0) body = codesters.Sprite(body_image, 0, 0) rand_numb2 = random.randint(0,5) legs_image = legs_list[rand_numb2] display_which_legs = codesters.Text(legs_image, 100, -83) legs = codesters.Sprite(legs_image, 0, -83) stage_index = int(head.ask("Choose an index between 0 and 5.")) stage_image = stage_list[stage_index] stage.set_background(stage_image)