Pilots keep asking Rocket the same question: how much fuel do I need? Each trip uses 12 units, but every pilot plans a different number of trips.
"I keep doing the same math in my head," Rocket says. Raven draws three boxes on her notepad. "What do you notice? First they tell you something. Then you work it out. Then you tell them the answer."
Nova labels the boxes with glowing letters. "Would you like a hint? Most programs have this same three-part shape."
| Part | What it does | In Python |
|---|---|---|
| Input | gets data from the user | input and int |
| Process | works something out | math, if, loops |
| Output | shows the result |
trips = int(input("How many trips? "))
per_trip = 12
fuel = trips * per_trip
print("Fuel needed:", fuel) | The screen shows | The user types |
|---|---|
| How many trips? | 5 |
| Fuel needed: 60 |
crew = int(input("Crew members? "))
days = int(input("Days away? "))
meals = crew * days * 3
print("Pack", meals, "meals") | The screen shows | The user types |
|---|---|
| Crew members? | 2 |
| Days away? | 4 |
| Pack 24 meals |
speed = int(input("Speed? "))
hours = int(input("Hours? "))
distance = speed * hours
print("Distance:", distance) | The screen shows | The user types |
|---|---|
| Speed? | 30 |
| Hours? | 4 |
| Distance: 120 |
| Statement | True or false? |
|---|---|
| Input comes before process. | ? |
| A program can have two inputs. | ? |
| The process line shows text on the screen. | ? |
| Output is often a print line. | ? |
You know the shape of a program now! Tomorrow the program will make choices with the user's answers.