2.2 Common boolean operators + data types and casting Flashcards
Types of Boolean operators
Types of Boolean operators
NOT
AND
OR
What does not do
Reverse the result, returns False if the result is true
Show an example where the NOT operator is used
while not end_of_file
This is the same as…
while end_of_file == False:
What are boolean operators used in
Boolean operators are used in what are called Boolean expressions.
Where can boolean operators be seen
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
Why are Boolean expressions called Boolean Expressions
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
Give an example where it would be more beneficial if a particular data type was used instead of the other
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.
What are the types of data types that variables and constants can hold
Variables and constants can hold:
Integer
Real (Float)
Character
String
Boolean
Define Boolean
Boolean – True or False, often called a “flag”.
When is the Boolean data type used
Boolean is used to track if something has happened or not
When should the Integer data type be used
The integer data type should only be used for data that requires calculations
When should the Real data type be used
Real - Only use for data that requires calculations
When should the String data type be used
String - Use for all data that is not calculated
Why is casing necessary
Casting is necessary so that sub-problems receive data in a format they are expecting
State some of things casting allows for/does
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