Open workspace
Python 1.5Code walkthrough9 min6 parts

Input, Output and Formatting

Read input and print results readably.

Loading your progress…Next: 1.6 Operators

In this lesson6 parts

  1. 01Output with print: arguments, sep and end, and why print returns None
  2. 02Formatting output with f strings, and the older format method
  3. 03Format specifiers: decimal places, thousands separators, width and alignment
  4. 04input: reading from the user, and converting the string it returns
  5. 05Why formatting changes the display and not the value, and when conversion fails
  6. 06Recap and your challenge

Key terms

The words this lesson introduces, each in one line. The module’s glossary collects them all.

"f" string · format specifier
f"{price:.2f}" · after the colon, how a value is shown

Quiz 5 questions

Answer each one in your head, or on paper, before you check it. Getting one wrong here is how the lesson sticks.

  1. 01

    A user types 3 at people = input("People: "). What is people * 2?

  2. 02

    What does print("The {item} costs {price}") print?

  3. 03

    What is f"{3.14159:.2f}"?

  4. 04

    What does r = print("x") bind to r?

  5. 05

    f"{100 / 3:.2f}" shows 33.33. Is the value now 33.33?

Practice

Problems to solve in your own notebook. Each states the problem, not the steps: working out the steps is the exercise. Level A applies the lesson, B combines it with earlier ones, C stretches it.

The self-checking notebook for this lesson is Notebook 3 · Input, Output and Operators.

Common mistakes

What you will see when it goes wrong, why it happens, and the fix.

Where it’s used

Where this lesson’s ideas turn up in real work.