← Code

Console bridge: text in, text out

Make programs that ask questions and answer back.

Start1. Print text
For teachers Usually Years 9–10 · 11 lessons

input(), print() and a text menu: the same logic as the turtle courses, as text in and text out. Every Python extension starts here.

  • Usually Years 9–10
  • Lessons 11
  • Do first Python functions and events
Teacher guide

Standards, in general: main focus: Trace algorithms for errors (8P06); touches on: Implement programs with functions (8P09). What this means

Text in, text out

Show text, ask a question, store the answer and join numbers onto text.

1Print textNot started

Show text on the screen with print, and join pieces of text into one line with +.

  1. Predict
  2. Investigate › Trace the lines
  3. Investigate › Spot the bug
  4. Investigate › Put the lines in order
  5. Make
Start lesson
2Ask and storeNot started

Ask a question with input, store the typed answer in a name, and use it in what the program says back.

  1. Predict
  2. Investigate › Follow the answer
  3. Investigate › Spot the bug
  4. Make
Start lesson
3Numbers into textNot started

Numbers from text

Turn typed text into numbers, and check it first so a typo does not crash the program.

4Text into numbersNot started

What input gives back is always text, so turn it into a number with int before calculating with it.

  1. Predict
  2. Investigate › Trace the lines
  3. Investigate › Spot the bug
  4. Modify
  5. Mix it up
  6. Make
Start lesson
5Check firstNot started

Ask the typed text whether it is all digits with isdigit, and use an if to choose, so a typo gets an answer instead of a crash.

  1. Predict
  2. Investigate › Trace the check
  3. Investigate › Spot the bug
  4. Modify
  5. Mix it up
  6. Make
Start lesson

Keep asking

Repeat with while, keep a running total, and read a whole guessing game.

6Repeat untilNot started

Keep running lines with while for as long as a condition is true, so a program can keep asking until it gets what it needs.

  1. Predict
  2. Investigate › Follow the loop
  3. Investigate › Zero times
  4. Investigate › Spot the bug
  5. Modify
  6. Mix it up
  7. Make
Start lesson
7Running totalNot started

Keep a total across the passes of a loop with +=, setting it to 0 once before the loop starts.

  1. Predict
  2. Investigate › Follow the total
  3. Investigate › Spot the bug
  4. Modify
  5. Mix it up
  6. Make
Start lesson
8Guess the numberNot started

Read a whole guessing game that uses loops, checks and a counter together, then change it and build a dice game from the same parts.

  1. Predict
  2. Run
  3. Investigate › Find the parts
  4. Investigate › Spot the bug
  5. Modify › A bigger range
  6. Modify › Only five tries
  7. Make
Start lesson

Menus and testing

A menu that keeps showing, and test cases written as a table.

9A menu that keeps showingNot started

Put a menu inside while True, choose with if and elif, and leave the loop with break when the person picks quit.

  1. Predict
  2. Investigate › Follow a session
  3. Investigate › Spot the bug
  4. Investigate › What does break do?
  5. Modify
  6. Mix it up
  7. Make
Start lesson
10Test with a tableNot started

Write test cases (what to type and what the program should reply) as lines that print True or False, and include a wrong choice.

  1. Predict
  2. Investigate › Read the tests
  3. Investigate › Spot the bug
  4. Modify › Add a test
  5. Modify › Fix the slip
  6. Mix it up
  7. Make
Start lesson

Console challenge

Build a console app with a menu, a checked number and a total.

11Challenge: a console appNot started

Read a working café till, change one thing and predict the result, then make a console app of your own with a menu, a checked number, a total and tests.

  1. Predict
  2. Investigate › Which part does the job?
  3. Investigate › Follow a change
  4. Modify
  5. Make
Start lesson

Project how-tos

Help for your own project. Open the one you need.

Progress is saved in this browser only. Nothing is sent anywhere.

For teachers: Teacher guide (notes, answers, solutions, slides and worksheets)