Community resourceWorksheet
1CP2-CT-4.1 Formatting output with format
Part 1 of 7 · 1CP2-CT-4 · Structures, validation and search
The formatting worksheet, separating the value a program holds from the way it is presented.
Students will:
- read a format descriptor for width, alignment and decimal places
- supply values in placeholder order
- explain why fixed width suits a column of prices
- construct a readable result row
- diagnose a formatting failure caused by the wrong type
Inside: 6 explanation cells, 3 multiple-choice questions, 1 Python task, 1 fill-in-the-blanks cell and 2 written answers. 14 marks, about 45 minutes.
Series: 1CP2-CT-4 · Structures, validation and search, part 1 of 7.
Shared by Coding PathwayVerified teacher
- 13 cells
- About 45 minutes
- CC BY-SA 4.0
- Shared 17 Aug 2026
Preview
The whole resource, exactly as a class sees it. Answers and marking are held back.
Formatting output with format
Programs should present information so an end user can read it quickly and unambiguously. Formatting controls how values appear: alignment, field width, signs and decimal places.
Pearson's current Programming Language Subset uses the string .format() method. This worksheet deliberately uses that form rather than f-strings.
1. Separate value from presentation
A placeholder {} is replaced by a supplied value. A descriptor after the colon controls presentation. <, > and ^ align left, right and centre. A width reserves the whole field. .2f displays a number in fixed-point notation with exactly two decimal places.
Formatting does not change the number stored in memory. It creates a string representation for output.
.2f displays gap 3 digits after the decimal point.- <
- >
- 2
- 8
- f
2. Supply values in placeholder order
message = "Name: {} Score: {}"
print(message.format("Ari", 17))
The first argument replaces the first placeholder; the second replaces the second. Positional placeholders therefore require deliberate ordering.
What is printed by print("{:>6.1f}".format(8.26))?
- A`8.26` with no reserved width
- B`8.2` right aligned in a field six characters wide
- C`8.3` right aligned in a field six characters wide
- DThe number 8.26 is permanently changed
Explain why {:>8.2f} may be useful for a column of prices.
Link alignment and precision to readability.
Students type their answer here.
3. Construct a readable result row
The variables below are supplied. Create layout using .format() placeholders so the item is left aligned in width 12 and the price is right aligned in width 8 with two decimal places. Store the formatted string in row, then print it.
Required exact output: Cable 3.50
item = "Cable"
price = 3.5
# Create layout, format row and print it.
4. Debug formatting precisely
A type descriptor must match the value. d is for denary integers; f is for fixed-point numeric output; s is for text. Supplying text to an f placeholder causes a runtime error. A width is a minimum field width, not a maximum string length.
A program runs "{:6.2f}".format("4.5") and fails. Identify the cause and give one correction.
Consider the type of the supplied argument.
Students type their answer here.
Which descriptor centres an integer in a field five characters wide?
- A`{:5.2f}`
- B`{:<5s}`
- C`{:^5d}`
- D`{:>5.2s}`
Which statement about formatting is accurate?
- AIt changes the stored numeric value.
- BIt controls how a value is represented in output.
- CIt validates whether input is acceptable.
- DIt searches a list for a matching item.
Route forward
You can build readable output using the current PLS .format() syntax. Next you will organise related rows and fields in a two-dimensional list.