第 19 步:如果我们的精灵不是太靠近会发生什么?现在,什么都没有!让我们改变它。

  • ,将Else拖到代码底部。

确保else:没有缩进,否则会导致错误! (前面不应该有空格)。

  • 单击图形选项卡,然后并拖出Sayelse:下缩进。
  • .say()命令前面的名称从sprite更改为michael

To navigate the page using the TAB key, first press ESC to exit the code editor.

stage.set_background("schoolentrance") stage.wait(2) stage.create_grid_overlay(50, "blue") stage.set_background_color("azure") emma = codesters.Sprite("person1") emma.set_size(0.5) michael = codesters.Sprite("person2") michael.set_size(0.5) emma_x = random.randint(-230,230) emma_y = random.randint(-230,230) emma.go_to(emma_x, emma_y) michael_x = random.randint(-230,230) michael_y = random.randint(-230,230) michael.go_to(michael_x, michael_y) delta_x = emma_x - michael_x delta_y = emma_y - michael_y distance = math.sqrt((delta_x**2) + (delta_y**2)) if distance <= 200: # add your code here emma.say("I am a sprite.") emma.load_image("person1_masked") michael.load_image("person2_masked")
  • Run Code
  • 提交作品
  • 下个活动
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)