Data types Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Integer

A

A number without a fraction or decimal.
Can be positive or negative.

e.g. 0, -3, 107463

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Real

A

Real numbers include all numbers that exist and their fractions and decimals

Integers are real number, but it is more efficient to declare them as integers so that less memory is needed

In OCR pseudocode, real numbers are declared as “float”

e.g.
float(“1.25”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Real

A

Real numbers include all numbers that exist and their fractions and decimals

Integers are real number, but it is more efficient to declare them as integers so that less memory is needed

In OCR pseudocode, real numbers are declared as “float”

e.g.
float(“1.25”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Boolean

A

A boolean value can only be true or false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Character

A

A character data type can store a single letter, number, or symbol

e.g. C, 3, !

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

String

A

A string can hold a lost of characters of any length.
When entered, they are enclosed in single or double quotation marks.

e.g. string = “Hello”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Importance of data type

A

Data used by a computer is only presented as 1s and 0s

The data type is needed so that the computer knows how to interpret the binary code so it can be used correctly

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Declaring data type

A

In some programming languages the data type must be declared, e.g. int age declares that the variable age stores an integer value

In other languages, the type does not have to be declared, and is instead inferred from the first type of data stored

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Casting

A

The conversion of one data type into another

e.g.
str(integer)
int(string)
float(string)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Identify a data type that would be suitable for the variable ‘response’ in the following situations and state why it is the most appropriate.

a) response = 10/7 [2]
b) response = input(“Please enter your name”) [2]
c) response = input(“Please enter your age in years”) [2]

A

a) real/float
It contains fractions or decimals

b) string
A person’s name consists of a sequence of characters

c) integer
It is a whole number without fractions or decimals

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

State what is returned by each of the following statements:

  • str(9)
  • int(999)
  • float(90)

[3]

A

9
999
90.0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly