F-String Formatting, online
Six activities your students do on their own devices. See who's finished, and their scores.
Learning
Understanding
Testing
F-String Formatting in one minute
What students need to know
int() converts a numeric string to an integer. str() converts a number to a string — useful for concatenation.
int() truncates — it cuts off the decimal, it does not round. str() always produces a string — not a float.
Mistakes students make
- Line 2 should use int() not str(). Use: number = int(text).
- Line 2 can't add string + int. Convert first: next_age = int(age) + 1.
- Line 2 can't join string + int. Use: message = "Score: " + str(score).
- Line 2 uses Int() with capital I. Python is case-sensitive. Use: int(value).
PREVIOUS · MODULE 9len() function
YOU ARE HERE · MODULE 10F-String Formatting
NEXT · MODULE 11Type Conversion
What students will learn in this module
Every question in Module 10
Quick questions
- What does
int("5")return?A5B"5" - What does
str(42)return?A42B"42" - What does
float("3.14")return?A3.14B"3.14" - What does
int(3.9)return?A4B3 - What does
str(100)convert 100 to?AA stringBA float
Key terms
Students type the meaning of:
int("5")float("3.14")str(42)int(3.9)
Match the pairs
int('hello')Match it to what it doesx = '5' print(x + 3)Match it to what it does
int('42')Match it to what it doesstr(100)Match it to what it doesprint(int(3.9))Match it to what it doesprint(float('2.5'))Match it to what it doesFill in the blanks
number = ___("42")text = str(___)
decimal = _____("300")year = input() year = ___(year)
score = 95 result = str(_____) print(result)
Spot the error
Question 1
Atext = "42"Bnumber = str(text)Cprint(number + 1)
Question 2
Aage = input("Enter age: ")Bnext_age = age + 1Cprint(next_age)
Question 3
Ascore = 95Bmessage = "Score: " + scoreCprint(message)
Question 4
Avalue = "3.14"Bdecimal = Int(value)Cprint(decimal)
Question 5
Aint("7")Bnum = "7"Cprint(num + 3)
