2.2 Common boolean operators + data types and casting Flashcards

1
Q

Types of Boolean operators

A

Types of Boolean operators

NOT

AND

OR

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

What does not do

A

Reverse the result, returns False if the result is true

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

Show an example where the NOT operator is used

A

while not end_of_file
This is the same as…
while end_of_file == False:

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

What are boolean operators used in

A

Boolean operators are used in what are called Boolean expressions.

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

Where can boolean operators be seen

A

Boolean expressions can be seen in, “if statements”, “while loops” and “ do …until loops”.

“If loop” - If a Boolean expression is true, then run some code

“While loop” - While this Boolean expression is true, run some code

“Do…until loop” - Do the following code, until this Boolean expression is true.

see relevant notebook file

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

Why are Boolean expressions called Boolean Expressions

A

These expressions are called Boolean expressions because that expression equates or evaluates to either true or false.

And also in them, we can use the Boolean operators

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

Give an example where it would be more beneficial if a particular data type was used instead of the other

A

There is little point in storing the whole number 22 in a real (float) data type, when the integer data type is perfectly capable of storing it and (the integer data type) takes up much less memory.

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

What are the types of data types that variables and constants can hold

A

Variables and constants can hold:
Integer
Real (Float)
Character
String
Boolean

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

Define Boolean

A

Boolean – True or False, often called a “flag”.

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

When is the Boolean data type used

A

Boolean is used to track if something has happened or not

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

When should the Integer data type be used

A

The integer data type should only be used for data that requires calculations

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

When should the Real data type be used

A

Real - Only use for data that requires calculations

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

When should the String data type be used

A

String - Use for all data that is not calculated

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

Why is casing necessary

A

Casting is necessary so that sub-problems receive data in a format they are expecting

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

State some of things casting allows for/does

A

Casting allows numbers to be manipulated as strings

Casting allows inputs that are always strings to become numbers,

X=str(X) casts the variable x to a string

X = int(X) casts the variable x to an integer

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

Select the most appropiate data types needed for the variables in this scenario

“A program is to be written which asks for a user’s name, age and telephone number. If they are aged 17 or under it informs them they are not eligible as they are too young. If they are 18 or over it stores their details and tells them they are eligible to vote”

A

Step 1: Study the scenario and work out all the variable that you would need.

key info:
name, age, telephone number, not eligible to vote, are eligible to ote