16 步:我们可以使用用户选择的索引从legs_list中获取一个值。

  • 在 LOGIC 中,转到并拖入Get Value at Index 。将名称更改为legs_image
  • 将列表名称从my_list更改为legs_list
  • 将索引更改为[ legs _index ]确保变量在方括号内。

    现在legs_image将根据用户在询问气泡中键入的索引号从列表中存储一个值。

    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"] body_list = ["middle1", "middle2", "middle3", "middle4", "middle5", "middle6"] legs_list = ["legs1", "legs2", "legs3", "legs4", "legs5", "legs6"] ######################################################################## # PLACE ALL OTHER CODE BELOW THIS # ######################################################################## stage_image = stage_list[1] stage.set_background(stage_image) random_head = random.randint(0, 5) head_image = head_list[random_head] # sprite = codesters.Sprite("image", x, y) head = codesters.Sprite(head_image, 0, 83) random_body = random.randint(0, 5) body_image = body_list[random_body] # sprite = codesters.Sprite("image", x, y) body = codesters.Sprite(body_image, 0, 0) legs_index = int(head.ask("Choose an index between 0 and 5."))
    • Run Code
    • 提交作品
    • 下个活动
    • Show Console
    • Reset Code Editor
    • Codesters How To (opens in a new tab)