Conditionals and Control Flow Flashcards
Control Flow
Fill this in later
Comparator
Check if a value is (or is not) equal to, greater than (or equal to), or less than (or equal to)
Eg.
- Equal to (==)
- Not equal to (!=)
- Less than ()
- Greater than or equal to (>=)
Boolean Operators
Compare statements and result in boolean values. Three types:
Eg.
- “and”, which checks if both statements are true
- “or”; wchih checks if at least one of the statements is true
- “not”, which fives the opposite of the statement
Order of Operations for Boolean Operators
- “not” is evaluated first
- “and” is evaluated next
- “or” is evaluated last.
Anything in parentheses () is evaluated as it’s own unit (solve inside the parentheses first)
Conditional statement syntax
a statement that executes some specific code after checking if its expression is true or false
Eg “if”, “Else”, “Elif”
“IF/Else” pair? Example?
When running “If” as a conditional statement, “Else” is used to provide an option in case the “If” expression is not true.
Eg. “If this expression is true, run this indented code block; otherwise, run this code after the else statement.”
“Elif” statement? Example?
Conditional statement; provides an alternative to an “if” statement in case it is false
Eg. “Otherwise, if the following expression is true, then do this.”
def greater_less_equal_5(answer): if answer > 5: return 1 elif answer < 5: return -1 else: return 0
print greater_less_equal_5(4) print greater_less_equal_5(5) print greater_less_equal_5(6)