Choosing a data type for a value

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

Choosing a data type for a value

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A game keeps a player's score and adds 10 points each time they win. Which data type fits the score best?
A Number, because you calculate with it
B Text, because it has digits in it
2. Which data type is best for a phone number like 0412 345 678?
A Text, because you never add phone numbers
B Number, because it is made of digits
3. A game needs a value called hasFinished to show if a level is done. Which type should it be?
A Text, because it is a word
B True/false, because the answer is yes or no
4. You want to join a first name and a last name to show 'Mia Chen' on a screen. Which type do you use?
A Number, because you combine two things
B Text, because you join and show it
5. Which sentence explains the choice for a student's age that you will add up to find a class total?
A Number, because I will add the ages
B Text, because I will add the ages

Match the Pairs

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

Left columnRight column
1score = 42 Aphone = "0412 345 678"
2hasFinished = True BA phone number is stored as a number, so the leading 0 is lost. It should be text: phone = "0412345678".
3A phone number is text because you never add it and you need to keep the leading 0. CA yes/no answer such as 'has finished' is a true/false value.
4Choose a number when you will calculate with the value, such as adding points. DA yes/no answer is stored as text. It should be true/false: hasFinished = True.
5phone = 0412345678 EA score is a whole number because you add it up and compare it to other scores.
6hasFinished = "yes" Ftotal = score + 10

Definitions

choose a data type

Fill in the Blanks

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

1.
score ← 42 // data type: ______
2.
phone ← "0412 345 678" // data type: ____
3.
hasFinished ← true // data type: __________
4.
phone is text _______ we never add it
5.
score is a number because we ___ scores

Spot the Error

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

Question 1
A score = 12
B bonus = 3
C total = score + "bonus"
D print(total)
Question 2
A phone = 0412345678
B print("Call " + phone)
C print(phone)
Question 3
A finished = "True"
B if finished:
C print("Well done!")
Question 4
A name = "Zoe"
B score = 25
C has_won = score > 20
D if has_won == "True":
E print(name, "wins!")
Question 5
A name = "Leo"
B qty = "six items"
C total = qty * 2
D print(name, total)

Answer Key

Choosing a data type for a value
Section A: Quick Questions
Q1
A — Number, because you calculate with it
Q2
A — Text, because you never add phone numbers
Q3
B — True/false, because the answer is yes or no
Q4
B — Text, because you join and show it
Q5
A — Number, because I will add the ages
Section B: Match the Pairs
Q1
score = 42 → A score is a whole number because you add it up and compare it to other scores.
Q2
hasFinished = True → A yes/no answer such as 'has finished' is a true/false value.
Q3
A phone number is text because you never add it and you need to keep the leading 0. → phone = "0412 345 678"
Q4
Choose a number when you will calculate with the value, such as adding points. → total = score + 10
Q5
phone = 0412345678 → A phone number is stored as a number, so the leading 0 is lost. It should be text: phone = "0412345678".
Q6
hasFinished = "yes" → A yes/no answer is stored as text. It should be true/false: hasFinished = True.
Section C: Definitions
Q1
choose a data type — Ask what you will do with the value: calculate with it (number), join or show it (text), or answer yes/no (true/false). A phone number is text because you never add it.
Section D: Fill in the Blanks
Q1
score ← 42 // data type: number
Q2
phone ← "0412 345 678" // data type: text
Q3
hasFinished ← true // data type: true/false
Q4
phone is text because we never add it
Q5
score is a number because we add scores
Section E: Spot the Error
Q1
C — A score is a whole number because we calculate with it. Adding the text "bonus" to a number is an error. It should be total = score + bonus.
Q2
A — A phone number is text because we never add it, and a number would lose its leading 0. It should be phone = "0412345678" in quotes.
Q3
A — 'Has finished' is a yes/no answer, so it should be the true/false value True. In quotes it is just text. It should be finished = True.
Q4
D — has_won already holds a true/false value, so we use it directly. Comparing it to the text "True" is wrong. It should be if has_won:.
Q5
B — We will multiply the quantity, so it must be a number. Text like "six items" can't be used in a calculation. It should be qty = 6.