← Years 7–8 Creating Digital Solutions

Converting types with int() and float()

input() gives text, so int() wraps it to turn the typed text into a whole number you can calculate with. Use float() for decimals. str() turns a number back into text.

Understanding Converting types with int() and float() in Years 7–8 Creating Digital Solutions

What it does: A number cannot be joined to a string with + until str() changes it into text. input() always gives back a string, even when the user types digits. float() keeps decimals. int() is for whole numbers, and int('4.50') causes an error. age is a string, so it must be converted with int(age) before you can add 1. After int() turns the text into numbers, + adds them. Joining '7' + '3' as strings would give '73'. int() can't convert text with a decimal point. Use float() for decimals. The fix is age = int(input("Age: ")). Then age + 1 works because age is a whole number.

Common mistakes: input() gives back text, so age + 1 would crash. Wrap it in int(): age = int(input("Age: ")). str() keeps the value as text, so score + 10 would crash. Use int() to turn the typed text into a whole number.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 50–125) and word search (Modules 3–125).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
A student types 5 when the program runs age = input(). What type is age?
An integer: 5A string (text): '5'
Matches
age = input("Age: ") print(age + 1)
↓
input() gives text, not a number. Adding 1 to text causes an error. Wrap input() in int() first.
Applying
Meanings
Term
int(input())
Meaning
input() gives text, so int() wraps it to turn the typed text into a whole number you can calculate with. Use float() for decimals. str() turns a number back into text.
Practice
age = int(input("Your age: "))
Testing
Gaps
age = (input("Age: "))
Check Answer
Spots
1age = input("Age: ")
2next_age = age + 1

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Nebula Cat' badge — Orbit Debugger, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. A student types 5 when the program runs age = input(). What type is age?
A. A string (text): '5' ✓
B. An integer: 5
input() always gives back a string, even when the user types digits.
2. Which line lets you add 1 to the number the user types?
A. score = input(int('Score: '))
B. score = int(input('Score: ')) ✓
int() wraps around input() so the typed text is turned into a whole number.
3. Which function should you use for a price like 4.50?
A. int()
B. float() ✓
float() keeps decimals. int() is for whole numbers, and int('4.50') causes an error.
4. What does this code do? age = input('Age: ') then print(age + 1)
A. It causes an error because you can't add a number to a string ✓
B. It prints the age plus one
age is a string, so it must be converted with int(age) before you can add 1.
5. Which line prints: You are 13 years old (age is the integer 13)?
A. print('You are ' + str(age) + ' years old') ✓
B. print('You are ' + age + ' years old')
str() turns the number into text so it can be joined to other text with +.

Match the Pairs

age = int(input("Age: ")) → Asks the user to type their age, then turns the typed text into a whole number
price = float("4.50") → Turns the text "4.50" into a decimal number
Use str() to turn a number into text so it can be joined to other text with + → print("Score: " + str(score))
Convert typed text to a whole number before adding to it → total = int(input()) + 5
age = input("Age: ") print(age + 1) → input() gives text, not a number. Adding 1 to text causes an error. Wrap input() in int() first.
print("You are " + 13 + " years old") → You cannot join a number to text with +. Change the number to text using str(13).

Key Term

int(input())
input() gives text, so int() wraps it to turn the typed text into a whole number you can calculate with. Use float() for decimals. str() turns a number back into text.

Fill in the Blanks

1. age = int(input("Age: ")) print(age + 1)
Hint: Type the function that turns the typed text into a whole number.
2. price = float(input("Price: ")) print(price * 2)
Hint: Type the function that turns text into a decimal number.
3. age = 12 print("You are " + str(age) + " years old")
Hint: Type the function that turns a number into text so it can be joined to a string.
4. total = int(input("Number: ")) * 2 print(total)
Hint: Type the function that reads what the user types and gives it back as text.
5. num = int(input("Number: ")) print(num * 2)
Hint: Type the variable name that holds the converted whole number.

Spot the Error

Question 1
A age = input("Age: ")
B next_age = age + 1
C print("Next year: " + str(next_age))
Line A — input() gives back text, so age + 1 would crash. Wrap it in int(): age = int(input("Age: ")).
Question 2
A name = input("Name: ")
B score = str(input("Score: "))
C total = score + 10
D print(name, total)
Line B — str() keeps the value as text, so score + 10 would crash. Use int() to turn the typed text into a whole number.
Question 3
A print("Shopping")
B price = int(input("Price: "))
C total = price * 3
D print("Total:", total)
Line B — A price like 2.50 has a decimal point, and int() can't convert text like that. Use float() for decimal numbers.
Question 4
A n = 5
B msg = "Pets: " + n
C print(msg)
Line B — You can't join a string and an int with +. Turn the number into text first: str(n).
Question 5
A a = int(input("First: "))
B b = int(input("Second: "))
C total = a + b
D print("Sum is " + total)
Line D — total is a number, so it can't be joined to text with +. Use str(total) to turn it into text.

Student with a class code? Join your class →