control flow Flashcards
what are conditional statments
This is the control flow of your program. In Python, your script will execute from the top down, until there is nothing left to run. It is your job to include gateways, known as conditional statements, to tell the computer when it should execute certain blocks of code. If these conditions are met, then run this function.
what is boolean expression
n order to build control flow into our program, we want to be able to check if something is true or not. A boolean expression is a statement that can either be True or False.
what does a Relational operators do
Relational operators compare two items and return either True or False. For this reason, you will sometimes hear them called comparators.
what does == and != do
Equals: ==
Not equals: !=
1 == 1 # True
2 != 4 # True
3 == 5 # False
‘7’ == 7 # False
is Friday is the best day of the week a boolean expression
No, this statement is an opinion and is not objectively True or False
how do we create booleans
why does True and False appear in different color
This is because True and False are their own special type: bool.
True and False are the only bool types, and any variable that is assigned one of these values is called a boolean variable.
Boolean variables can be created in several ways. The easiest way is to simply assign True or False to a variable:
set_to_true = True
set_to_false = False
how do you create a boolean varible
Boolean variables can be created in several ways. The easiest way is to simply assign True or False to a variable:
set_to_true = True
set_to_false = False
how do you variable equal to a boolean expression.
bool_one = 5 != 7
bool_two = 1 + 1 != 2
bool_three = 3 * 3 == 9
These variables now contain boolean values, so when you reference them they will only return the True or False values of the expression they were assigned.
print(bool_one) # True
print(bool_two) # False
print(bool_three) # True
What is an if statement
If “it is raining” == True then the rest of the conditional statement will be executed and you will bring an umbrella.
what is the colon : used for in if statments
if is_raining:
print(“bring an umbrella”)
You’ll notice that instead of “then” we have a colon, :. That tells the computer that what’s coming next is what should be executed if the condition is met.
what are all the other relational operator symbols
> greater than
>= greater than or equal to
< less than
<= less than or equal to
How would you set a write a program that checks if our users are over 13 when showing them a PG-13 movie
if age <= 13:
print(“Sorry, parental control required”)
This function will take the user’s age and compare it to the number 13. If age is less than or equal to 13, it will print out a message.
what is an boolean operateor
you can build larger boolean expressions using boolean operators. These operators (also known as logical operators) combine smaller boolean expressions into larger boolean expressions.
what are the 3 boolean operators
- and
- or
- not