View as PDF

COMPUTING AND DIGITAL LITERACY

Data Types

Difficulty level: Easy

Computing and Digital Literacy

This document was made by AI and there may be mistakes. If a question or answer looks wrong, use the Flag a mistake button to let Brett know so he can fix it.

Overview of the concept

This is how a computer tells a number apart from a word or a yes-or-no answer. Your age is a number it can add, your name is text it can display, and whether you are logged in is a yes or no it can check. Mixing them up breaks a program, like trying to add two names together. Knowing the type tells you what you are allowed to do with a piece of information.

Worked examples

Example 1

What type is each of these values: 12, 4.50, “Sam”, True?

Solution

The one rule to remember first: the type is decided by what the value looks like, not what it means.

12 is a whole number, so it is an integer. 4.50 has a decimal point, so it is a float.

“Sam” is text in quotes, so it is a string. True is a yes-or-no value, so it is a boolean.

Example 2

What is 12 + 3, and what is “12” + “3”?

Solution

12 + 3 adds two numbers: 12 + 3 = 15.

“12” + “3” joins two pieces of text: “12” + “3” = “123”.

Check the type before predicting the result: the same symbol does a different job on numbers and on text.

Practice questions

1

What type is 42?

2

What type is 3.5?

3

What type is “hello”?

4

What type is True?

5

What is “12” + “3” in most languages?

7

Which type holds yes-or-no values?

8

Is “42” a number or text?

9

Which type would a price such as 4.99 be?

10

A program stores a password “3845” and then tries to add 1 to it. What goes wrong?

ANSWER KEY

1. Integer

2. Float

3. String

4. Boolean

5. “123” (the texts join)

6. 15

7. Boolean

8. Text (a string)

9. Float

10. It fails: the password is text, so you cannot add a number to it.