第4步:命名我们的函数!

函数命名为与功能相关的名称。这让你的代码更容易阅读和使用。

  • 点击 ,将 Define Function 拖动到程序底部。
  • 将函数的名称从 my_function 更改为 bridge_scene
  • Drawbridge 背景放置在函数内部。在 def 行下缩进4个空格。

就像循环和条件语句一样,如果函数为空,那么它会导致错误。

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()
  • Run Code
  • 提交作品
  • 下个活动
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)