F-String Formatting, online

Six activities your students do on their own devices. See who's finished, and their scores.

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

Discover other journeys with this module

What students will learn in this module

Every question in Module 10

Quick questions

  1. What does int("5") return?A5B"5"
  2. What does str(42) return?A42B"42"
  3. What does float("3.14") return?A3.14B"3.14"
  4. What does int(3.9) return?A4B3
  5. 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 does
x = '5'
print(x + 3)
Match it to what it does
int('42')Match it to what it does
str(100)Match it to what it does
print(int(3.9))Match it to what it does
print(float('2.5'))Match it to what it does

Fill in the blanks

  1. number = ___("42")
  2. text = str(___)
  3. decimal = _____("300")
  4. year = input()
    year = ___(year)
  5. 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)