A recipe
Cooks read the steps and get the ingredients ready before they turn on the stove.
10THINK LIKE A PROGRAMMER Β· PLAN
Write the steps in plain words as # comments. Then turn each one into Python.
IN REAL LIFE
People plan in plain words before they start.
Cooks read the steps and get the ingredients ready before they turn on the stove.
Before a trip, your family looks at the map and picks the way.
You write a list: find pictures, glue them, write the title. Then you start.
LOOK FIRST
What comes in? What do you do with it? What comes out?
Write each step in plain words after a #. Python skips those lines.
For each step, choose a box, an if, a loop, or a function.
Pick the tool: keep something β box =. Choose β if. Repeat β loop. Use the same steps many times β function def.
LOOK FIRST
Each step of the plan becomes one line of Python.
cookies = 12Plan: keep the number of cookies. Input, so a box.friends = 4Plan: keep the number of friends. Another box.each = cookies // friendsPlan: share them out. The work: // divides into whole cookies.print("Each friend gets", each)Plan: show the answer. The output.RUN IT
Guess first. Then run real Python and check.
# Plan: share cookies
# 1. Keep the numbers (input)
cookies = 12
friends = 4
# 2. Share them out (work)
each = cookies // friends
# 3. Show it (output)
print("Each friend gets", each)What will Python show?
PyBot's hint
Ready. Press Run Python.
Pyodide 314.0.3 runs CPython in your browser with WebAssembly.
Open-source under the Mozilla Public License 2.0. License
Now change one thing: Change friends to 6 and run again. Which step of the plan changed?
YOUR TURN
Try each tiny question. A wrong answer becomes something to review.
What is the best first step?
# 2. Add the pointsWhat does Python do with this line?
Which part is the work?
# If it rains, say:
# take an umbrellaWhich tool fits this step?
# Say hi to each
# friend in the listWhich tool fits this step?
# Show the game title
# at the start,
# after a win,
# and at the endWhich tool fits this step?
# 3. Show the totalWhich line of Python does this step?
Which plan order works?
PyBot wrote the plan, but steps 2 and 3 have no code yet. Write one line under each.
Total points: 12OUTPUT
The plan says to greet each friend, but the code only greets one. Use a loop.
Hi Ana Hi Leo Hi MiaOUTPUT
Want a fresh start? Clear only this page.
Find the input, the work, and the output. Write each step as a # comment, then turn it into Python with the right tool.