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

Crew Quest

Crew Quest: Human Console
// Programs that ask questions
⏱ about 15 min

Crew Quest: Human Console

The station screens are off for an update. "We can still run programs," Raven says. "One of us can be the computer."

Rocket volunteers to be the user. Raven reads the program line by line, out loud. When she reaches input, she asks the prompt and waits. "What do you notice?" she says. "I cannot go on until you answer."

Nova keeps the trace table glowing in the air. "Every answer changes the path," she says.

  1. input shows a prompt, waits, and gives back a string.
  2. int turns a string of digits into a number.
  3. Most programs follow input, process, output.
  4. An if can check the user's answer. Use lower to accept any capitals.
  5. A loop can ask one question for each item in a list.
β—‡ HUMAN CONSOLE
One person is the computer. One person is the user.
The computer reads the program below, one line at a time.
At each input, the computer asks the prompt and waits.
Keep a trace table on paper. Then swap jobs and pick new answers.
trips = int(input("Trips? "))
fuel = int(input("Fuel units? "))
need = trips * 12
if fuel >= need:
    print("Go!")
else:
    print("Need", need - fuel, "more")
The user types 4, then 30. What number does the program show?
WHY THIS EXERCISEThis checks input, int, process and a choice all at once.
BONUS RECAP
  • Read the question.
  • Tap your answer.
What does int("8") + 2 give?
Which part of a program is the print line?
What does input("Name? ") give back?

Fantastic teamwork! Next week, you will write functions that give back answers.

← Friday