Choosing data types for input, storage and output

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Choosing data types for input, storage and output

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What data type does input() always return in Python?
A str (a string of text)
B int (a whole number)
2. A user types 25 for their age: age = input('Age: '). What is stored in age?
A The string '25'
B The integer 25
3. Which line stores a whole-number input so you can do arithmetic on it?
A qty = input(int('Qty: '))
B qty = int(input('Qty: '))
4. Which data type is best for storing a price such as 4.95 that was typed in by the user?
A int(input('Price: '))
B float(input('Price: '))
5. Which variable should store whether a student has paid, to be used in an if statement?
A paid = True (a bool)
B paid = 'True' (a str)

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1age = int(input("Age: ")) Ainput() returns a str, so age was never converted to an int. Adding 1 to a str causes a TypeError.
2print(f"Total: ${total:.2f}") Bprice = float(input("Price: "))
3Input always arrives as a str, even when the user types digits, so it must be converted before storing as a float CAn int cannot be joined to a str with +. The stored number was not converted to text for output.
4A number stored as an int must be turned back into text with str() before joining it to other text for output DFormats a stored float as text with 2 decimal places for output
5age = input("Age: ") next_age = age + 1 EReads the typed text from the user and converts it to an int so it can be stored as a number
6score = 42 print("Score: " + score) Fprint("Score: " + str(score))

Definitions

int(input())

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
age = ___(input("Enter your age: "))
2.
price = _____(input("Enter the price: "))
3.
total = 12 print("Total: " + ___(total))
4.
score = 87 print(_"Score: {score}%")
5.
name = input("Name: ") print(type(name) == ___)

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A age = input("Age: ")
B age = int(age)
C next_age = age + "1"
D print(f"Next year: {next_age}")
Question 2
A cost = float(input("Cost: "))
B qty = int(input("Qty: "))
C total = cost * qty
D print("Total: " + total)
Question 3
A score = input("Score: ")
B score = str(score)
C if score >= 50:
D print("Pass")
Question 4
A m = input("Metres: ")
B cm = m * 100
C print(f"{cm} cm")
Question 5
A name = input("Name: ")
B mark = int(input("Mark: "))
C print(name + " got " + mark)

Answer Key

Choosing data types for input, storage and output
Section A: Quick Questions
Q1
A — str (a string of text)
Q2
A — The string '25'
Q3
B — qty = int(input('Qty: '))
Q4
B — float(input('Price: '))
Q5
A — paid = True (a bool)
Section B: Match the Pairs
Q1
age = int(input("Age: ")) → Reads the typed text from the user and converts it to an int so it can be stored as a number
Q2
print(f"Total: ${total:.2f}") → Formats a stored float as text with 2 decimal places for output
Q3
Input always arrives as a str, even when the user types digits, so it must be converted before storing as a float → price = float(input("Price: "))
Q4
A number stored as an int must be turned back into text with str() before joining it to other text for output → print("Score: " + str(score))
Q5
age = input("Age: ") next_age = age + 1 → input() returns a str, so age was never converted to an int. Adding 1 to a str causes a TypeError.
Q6
score = 42 print("Score: " + score) → An int cannot be joined to a str with +. The stored number was not converted to text for output.
Section C: Definitions
Q1
int(input()) — input() always returns a str, so convert it (e.g. with int) to store it as a number. Turn it back into text with str() or an f-string when you output it.
Section D: Fill in the Blanks
Q1
age = int(input("Enter your age: "))
Q2
price = float(input("Enter the price: "))
Q3
total = 12 print("Total: " + str(total))
Q4
score = 87 print(f"Score: {score}%")
Q5
name = input("Name: ") print(type(name) == str)
Section E: Spot the Error
Q1
C — age was converted to an int on line 2, so adding the str "1" causes a TypeError. It should be age + 1, with both values numbers.
Q2
D — total is a float, and you can't join a float to a str with +. Convert it to text with str(total) or use an f-string.
Q3
B — str() keeps the score as text, so score >= 50 compares a str to an int and causes a TypeError. It should be int(score) to store the score as a number.
Q4
A — input() always returns a str, so m * 100 would repeat the text 100 times instead of calculating. It should be wrapped in float(): m = float(input("Metres: ")).
Q5
C — mark is an int, and + cannot join a str and an int, so this causes a TypeError. Use an f-string such as f"{name} got {mark}" or str(mark).