Conditionals and Control Flow Flashcards

1
Q

Control Flow

A

Fill this in later

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

Comparator

A

Check if a value is (or is not) equal to, greater than (or equal to), or less than (or equal to)

Eg.

  1. Equal to (==)
  2. Not equal to (!=)
  3. Less than ()
  4. Greater than or equal to (>=)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Boolean Operators

A

Compare statements and result in boolean values. Three types:

Eg.

  1. “and”, which checks if both statements are true
  2. “or”; wchih checks if at least one of the statements is true
  3. “not”, which fives the opposite of the statement
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Order of Operations for Boolean Operators

A
  1. “not” is evaluated first
  2. “and” is evaluated next
  3. “or” is evaluated last.
    Anything in parentheses () is evaluated as it’s own unit (solve inside the parentheses first)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Conditional statement syntax

A

a statement that executes some specific code after checking if its expression is true or false

Eg “if”, “Else”, “Elif”

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

“IF/Else” pair? Example?

A

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.”

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

“Elif” statement? Example?

A

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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly