Everything else is ready: study the parts, the key terms and the quiz below.
- Part 11Output with print: arguments, sep and end, and why print returns None
- Part 22Formatting output with f strings, and the older format method
- Part 33Format specifiers: decimal places, thousands separators, width and alignment
- Part 44input: reading from the user, and converting the string it returns
- Part 55Why formatting changes the display and not the value, and when conversion fails
- Part 66Recap and your challenge
Input, Output and Formatting
Read input and print results readably.
In this lesson6 parts
- 01Output with print: arguments, sep and end, and why print returns None
- 02Formatting output with f strings, and the older format method
- 03Format specifiers: decimal places, thousands separators, width and alignment
- 04input: reading from the user, and converting the string it returns
- 05Why formatting changes the display and not the value, and when conversion fails
- 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.
- 01
A user types
3atpeople = input("People: "). What ispeople * 2? - 02
What does
print("The {item} costs {price}")print? - 03
What is
f"{3.14159:.2f}"? - 04
What does
r = print("x")bind tor? - 05
f"{100 / 3:.2f}"shows33.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.