第9步:现在我们来调用函数!确保调用的位置在函数外部!

调用一个函数需要使用函数名称,后面加一组空的括号 ()

  • 点击 并拖出 Function Call
  • 将函数调用中的名称更改为 battle_scene
  • 点击 运行 以在控制台上查看你的函数。


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

sprite = codesters.Sprite("knight1", -175, -150) sprite.set_speed(2) def park_scene(): stage.set_background("park") sprite.say("I should hurry to the castle!") sprite.move_forward(550) park_scene() def bridge_scene(): stage.set_background("drawbridge") sprite.go_to(-175, -150) sprite.say("I made it!") stage.wait(2) bridge_scene() def battle_scene(): dragon = codesters.Sprite("dragon", 150, -150) sprite.say("Oh no a dragon!") sprite.move_forward(300) dragon.turn_left(360) dragon.move_down(200) sprite.say("The path is clear!")
  • Run Code
  • 提交作品
  • 下个活动
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)