Type Conversion

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

Type Conversion

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. After name = "Alice", what is f"Hi {name}"?
A Hi Alice
B Hi {name}
2. After age = 15, what is f"I am {age}"?
A I am 15
B I am {age}
3. What letter starts an f-string?
A s
B f
4. Where do variables go in f-strings?
A Inside {}
B After +
5. After city = "Melbourne", what is f"Welcome to {city}"?
A Welcome to {city}
B Welcome to Melbourne

Match the Pairs

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

Left columnRight column
1name = 'Bob' print('Hi {name}') AError: Missing f prefix
2age = 10 f'Age: {age'} BOutput: 7 * 2 = 14
3x = 5 f'Value: {x}' CInvalid: Unclosed brace
4f'{2 + 2}' DOutput: Hi Ali!
5name = 'Ali' print(f'Hi {name}!') EValid: f-string syntax
6n = 7 print(f'{n} * 2 = {n*2}') FOk: Expressions inside {}

Definitions

name = "Alice"

Fill in the Blanks

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

1.
greeting = _"Hello {name}"
2.
age = 12 message = f"I am _____ years old"
3.
city = "Sydney" text = f"Welcome to ______"
4.
score = 85 result = f"Your score: {_____}"
5.
first = "Jo" last = "Li" full = f"{_____} {____}"

Spot the Error

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

Question 1
A name = "Alice"
B message = "Hello {name}"
C print(message)
Question 2
A age = 15
B info = f"I am age years old"
C print(info)
Question 3
A city = "Melbourne"
B text = f"Welcome to [city]"
C print(text)
Question 4
A first = "Bob"
B last = "Smith"
C name = f"{first} {last}"
D greeting = f"Hello (name)"
E print(greeting)
Question 5
A score = 100
B message = f"Score: {score}"
C age = 15
D info = "Age: {age}"
E print(info)

Answer Key

Type Conversion
Section A: Quick Questions
Q1
A — Hi Alice
Q2
A — I am 15
Q3
B — f
Q4
A — Inside {}
Q5
B — Welcome to Melbourne
Section B: Match the Pairs
Q1
name = 'Bob' print('Hi {name}') → Error: Missing f prefix
Q2
age = 10 f'Age: {age'} → Invalid: Unclosed brace
Q3
x = 5 f'Value: {x}' → Valid: f-string syntax
Q4
f'{2 + 2}' → Ok: Expressions inside {}
Q5
name = 'Ali' print(f'Hi {name}!') → Output: Hi Ali!
Q6
n = 7 print(f'{n} * 2 = {n*2}') → Output: 7 * 2 = 14
Section C: Definitions
Q1
name = "Alice" — Assigns the string Alice to the variable name.~~f"Hello {name}"
Section D: Fill in the Blanks
Q1
greeting = f"Hello {name}"
Q2
age = 12 message = f"I am {age} years old"
Q3
city = "Sydney" text = f"Welcome to {city}"
Q4
score = 85 result = f"Your score: {score}"
Q5
first = "Jo" last = "Li" full = f"{first} {last}"
Section E: Spot the Error
Q1
B — Line 2 is missing f. Should be: message = f"Hello {name}"
Q2
B — Line 2 is missing curly braces. Should be: f"I am {age} years old"
Q3
B — Line 2 uses [ ] instead of { }. Should be: f"Welcome to {city}"
Q4
D — Line 4 uses (name) instead of {name}. Should be: f"Hello {name}"
Q5
D — Line 4 is missing f. Should be: info = f"Age: {age}"