F-String Formatting

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

F-String Formatting

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What does int("5") return?
A 5
B "5"
2. What does str(42) return?
A 42
B "42"
3. What does float("3.14") return?
A 3.14
B "3.14"
4. What does int(3.9) return?
A 4
B 3
5. What does str(100) convert 100 to?
A A string
B A float

Match the Pairs

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

Left columnRight column
1int('hello') AError: str + int not allowed
2x = '5' print(x + 3) BError: Cannot convert to int
3int('42') COutput: 2.5
4str(100) DValid: Returns 42
5print(int(3.9)) EOutput: 3
6print(float('2.5')) FOk: Returns '100'

Definitions

int("5")

Fill in the Blanks

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

1.
number = ___("42")
2.
text = str(___)
3.
decimal = _____("300")
4.
year = input() year = ___(year)
5.
score = 95 result = str(_____) print(result)

Spot the Error

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

Question 1
A text = "42"
B number = str(text)
C print(number + 1)
Question 2
A age = input("Enter age: ")
B next_age = age + 1
C print(next_age)
Question 3
A score = 95
B message = "Score: " + score
C print(message)
Question 4
A value = "3.14"
B decimal = Int(value)
C print(decimal)
Question 5
A int("7")
B num = "7"
C print(num + 3)

Answer Key

F-String Formatting
Section A: Quick Questions
Q1
A — 5
Q2
B — "42"
Q3
A — 3.14
Q4
B — 3
Q5
A — A string
Section B: Match the Pairs
Q1
int('hello') → Error: Cannot convert to int
Q2
x = '5' print(x + 3) → Error: str + int not allowed
Q3
int('42') → Valid: Returns 42
Q4
str(100) → Ok: Returns '100'
Q5
print(int(3.9)) → Output: 3
Q6
print(float('2.5')) → Output: 2.5
Section C: Definitions
Q1
int("5") — Converts the string "5" to the integer 5.~~float("3.14")
Section D: Fill in the Blanks
Q1
number = int("42")
Q2
text = str(100)
Q3
decimal = float("300")
Q4
year = input() year = int(year)
Q5
score = 95 result = str(score) print(result)
Section E: Spot the Error
Q1
B — Line 2 should use int() not str(). Use: number = int(text)
Q2
B — Line 2 can't add string + int. Convert first: next_age = int(age) + 1
Q3
B — Line 2 can't join string + int. Use: message = "Score: " + str(score)
Q4
B — Line 2 uses Int() with capital I. Python is case-sensitive. Use: int(value)
Q5
A — Converts but doesn't save the result. Use: num = int(num)