More Reeborg!

Overview
You'll learn to define your own functions — reusable pieces of code with a name you choose — while you send Reeborg on new missions.
Builds on
Meet Reeborg!. Keep your saved programs from that lab.
Before you start
Each mission below has its own button that loads the right world. Save your work after every world — you'll turn all of them in at the end. The world names (such as Step 4) are Reeborg's labels; the numbered instructions below are this lab's action steps.
You've got it when…
- Your Step 4 solution turns right with one call to
turn_right()wherever it used threeturn_left()calls. - Your
pick_two_berries()function is defined once and used four times to clear the garden. - You've saved a
.pyfile for both steps.
Collaboration & AI
Work: On your own. You can compare notes with a neighbor, but write your own commands.
AI — AIAS Level 1, No AI: Write and debug your own code without AI assistance. What the levels mean.
Step 4, Revisited — Your First Function
-
Work through this world, then save your program.
You probably noticed that Reeborg has no function to turn right. It can only turn left, and we have to make three left turns to turn right.
We can create our own function. Functions are how we create pieces of code that we can reuse. We use the word
defto define functions. Enter the following code at the top of your file:Warning
The code that is part of your new
turn_right()function must be indented. Use the Tab key to indent code.Your mission: add the
turn_right()function to the top of yourStep 4.pyfile, then use it in your original solution to replace the places where Reeborg callsturn_left()three times to make a right turn.
Step 5 — The Strawberry Garden
-
Work through this world, then save your program.
Your mission: write code to pick all the strawberries from the rows in the garden and put them on the ground in the center.
Define a
pick_two_berries()function that picks up two strawberries and puts them on the ground. Use it four times as part of your solution.Tip
Assume that your function starts with Reeborg standing in the center and facing a row of two strawberries.
Check Your Work
- Run both missions. Check that
turn_right()replaces each three-left-turn sequence and thatpick_two_berries()is called four times. Save the updatedStep 4.pyandStep 5.py.
Turn It In
- Submit these Python source files:
-
Step 4.py(updated function version) -
Step 5.py
Choose the updated file
Downloads may add a number to duplicate filenames. Submit the version of Step 4.py that uses your new function.
How It's Graded
One score, from 0–4, covers your submitted Python source files.
| Score | Evidence |
|---|---|
| 4 Excellent | Both files work. Step 4 uses turn_right() in place of three left turns; Step 5 defines pick_two_berries() once and calls it four times to collect and deposit all berries. |
| 3 Above Average | All required programs work and use the required constructs, with minor errors or omissions in code organization. |
| 2 Average | Some required work functions, but a mission, required construct, or source file is missing. |
| 1 Below Average | Programs are largely incomplete or nonfunctional. |
| 0 Failing | No submission or no evidence of the required work. |
Credit: Adapted from Dan Schellenberg's Computer Science 20 textbook.