Community resourceWorksheet
1CP2-CT-1.4 Data types, input, conversion and debugging
Part 4 of 7 · 1CP2-CT-1 · Programming foundations
The data types worksheet, covering why keyboard input arrives as text and what has to happen next.
Students will:
- choose the appropriate primitive type for a given value
- convert input to a number before calculating with it
- build a complete input, processing and output program
- read a runtime error and say what caused it
- work through one full debugging cycle and state the amendment
Inside: 9 explanation cells, 3 multiple-choice questions, 2 Python tasks, 3 fill-in-the-blanks cells and 1 written answer. 20 marks, about 45 minutes.
Series: 1CP2-CT-1 · Programming foundations, part 4 of 7.
Shared by Coding PathwayVerified teacher
- 18 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.
Data types, input, conversion and debugging
The previous worksheet introduced named storage and assignment. This worksheet adds the type of each stored value and keyboard input.
You will learn how to:
- distinguish required primitive data types and their Python names;
- explain that
input()returns text; - convert suitable text using
int()orfloat(); - complete input-process-output programs;
- read, locate and repair a simple conversion runtime error.
Syntax and logic errors are named for orientation, but independent debugging focuses only on the locally modelled conversion fault.
1. Primitive data types
A data type describes the kind of value and the operations that make sense for it.
| Specification type | Meaning | Python type used here | Example |
|---|---|---|---|
| Integer | Whole number | int | 18 |
| Real | Number with a fractional part | float | 2.5 |
| Boolean | Logical truth value | bool | True |
| Character | One character | one-character str | "A" |
Python uses str for both one character and longer text. A full string is a structured sequence of characters and is studied more deeply later.
12 has Python type label 1. The value 3.5 has type label 2. The value False has type label 3. The one-character value "Q" is represented by type label 4.- bool
- float
- int
- list
- str
Which type is most appropriate for storing the number of students present?
- ABoolean
- BCharacter
- CInteger
- DReal
2. Keyboard input arrives as text
input() displays a prompt, waits for the user and returns the entered characters as text.
name = input("Name: ")
print(name)
Text can be output directly. Arithmetic needs a numerical type. int() converts suitable whole-number text and float() converts suitable decimal text:
tickets = int(input("Tickets: "))
total = tickets * 4
print(total)
If the user enters 3, tickets stores integer 3 and the program outputs 12.
tickets = int(input("Tickets: "))
total = tickets * 4
print(total)boxes = label 1(input("Boxes: "))
weight = label 2(input("Weight: "))
ready = label 3- False
- float
- input
- int
- str
3. A complete input-process-output program
Requirement: ask for a number of packs and items per pack, calculate the total and report it.
packs = int(input("Packs: "))
items_per_pack = int(input("Items per pack: "))
total = packs * items_per_pack
print("Total: " + str(total))
| IPO role | Program evidence |
|---|---|
| Input | two input() calls, each converted to int |
| Processing | multiplication assigned to total |
| Output | informative label and the calculated value |
The names make the program readable. The conversion occurs before arithmetic. For the output, str(total) converts the number to text so it can be concatenated with the label.
int(input(...)) supplies converted label 1. The multiplication is the label 2. print() produces the label 3.- input
- output
- processing
- runtime error
- string
4. Errors and the first debugging cycle
Three error categories recur throughout the course:
- Syntax error: the rules of the programming language have been broken.
- Runtime error: the program begins executing but an operation cannot be completed.
- Logic error: the program runs but produces incorrect behaviour or output.
For now, concentrate on one runtime example:
age = int(input("Age: "))
print(age)
If the entered text is fourteen, int() cannot convert it to a whole number. Python stops while the program is running. A useful debugging cycle is read → locate → explain → amend or use suitable data → rerun.
Reading the evidence
A shortened message might say:
ValueError: invalid literal for int() with base 10: 'fourteen'
Read it from the task backwards:
- Locate: the failing operation is
int(). - Explain: the supplied text is not a valid whole-number representation.
- Respond: supply suitable numeric text, or redesign the program later with validation when that technique has been taught.
- Rerun: confirm the program now completes.
Do not call this a syntax error. Python understood the line and started executing it.
Why does int("twelve") cause the modelled runtime error?
- AQuotation marks are never allowed in Python.
- BThe text cannot be converted to a whole-number value by int().
- CThe program has used multiplication instead of addition.
- DThe identifier int is too short.
5. Supported input program
Complete the program so it:
- inputs
packsand converts it to an integer; - inputs
items_per_packand converts it to an integer; - multiplies them into
total; - outputs
Total:followed by the value.
It will be tested with 4 and 6, then 3 and 9. Do not add validation yet.
packs = input("Packs: ")
items_per_pack = input("Items per pack: ")
total = packs + items_per_pack
print("Total: " + str(total))6. Apply the debugging cycle
A student enters 2.5 into this program:
distance = int(input("Distance: "))
print(distance)
The program stops during conversion. Your response must identify the failing operation, explain why this particular text is unsuitable for int(), and give a suitable amendment when fractional distances are allowed.
Explain the runtime error and state the amendment needed when the distance may contain a fractional part.
Use the chain locate, explain, amend. Name the conversion function that should be used instead.
Students type their answer here.
7. One final distinction
Type choice and conversion are related but different decisions:
- choose
intbecause a count is a whole number; - choose
floatbecause a measurement may contain a fractional part; - convert text from
input()into the chosen numerical type before arithmetic.
A good explanation names both the nature of the data and the operation that requires conversion.
A user enters 3.75 for a journey time in hours. Which expression is most appropriate?
- Abool(input("Hours: "))
- Bfloat(input("Hours: "))
- Cint(input("Hours: "))
- Dstr(input("Hours: "))
Route forward
You can now choose primitive types, convert keyboard input, complete an IPO program and handle one carefully modelled runtime conversion fault. Next you will represent sequence visually using Pearson's flowchart conventions.