← Back to course
Code Crew G4 / Week 09 / Wednesday
3/6
Week 09 Β· Input, process, output

Wednesday

Input, process, output
// Programs that ask questions
⏱ about 15 min

Wednesday: Input, process, output

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."

The three parts

PartWhat it doesIn Python
Inputgets data from the userinput and int
Processworks something outmath, if, loops
Outputshows the resultprint
trips = int(input("How many trips? "))
per_trip = 12
fuel = trips * per_trip
print("Fuel needed:", fuel)
The screen showsThe user types
How many trips?5
Fuel needed: 60
Which line is the input? Type its line number.
Which line is the process? Type its line number.
The user types 8. What number shows after Fuel needed:?
crew = int(input("Crew members? "))
days = int(input("Days away? "))
meals = crew * days * 3
print("Pack", meals, "meals")
The screen showsThe user types
Crew members?2
Days away?4
Pack 24 meals
Run the meal program again. The user types 3, then 5. How many meals?
WHY THIS EXERCISETwo inputs feed one process. The output changes with every run.
PUT THE LINES IN ORDER: ASK FOR A DISTANCE, DOUBLE IT, THEN SHOW IT
  • ?print(there_and_back)
  • ?there_and_back = km * 2
  • ?km = int(input("Distance? "))
WHY THIS EXERCISEA value must exist before you can work with it or show it.
Try it
Think of a question a pilot might ask.
Draw three boxes: input, process, output. Fill them in.

Practice lab: how far?

speed = int(input("Speed? "))
hours = int(input("Hours? "))
distance = speed * hours
print("Distance:", distance)
The screen showsThe user types
Speed?30
Hours?4
Distance: 120
Which line is the output? Type its line number.
The user types 15, then 2. What number shows?
The user types 20, then 5. What number shows?
NAME THE PART
  • Read the question.
  • Tap your answer.
Which part is distance = speed * hours?
Which part is the print line?
Why use int on both inputs?
StatementTrue 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.?
WHY THIS EXERCISEEach part has one job. Together they make a program.
A program asks for lamps, then prints lamps * 4 for the bulbs needed. The user types 6. What shows?
WHY THIS EXERCISEOne input, one process, one output.

You know the shape of a program now! Tomorrow the program will make choices with the user's answers.

← Tuesday