What is if?
→ non-exclusive: if is a reserved python key word used in conditions and anything after must be evaluate as being either true or false (ex. If a<50 → true or false?)
–> executes a block of code if its condition is True
What is a code block?
→ code block: all code intended after if statement executed if condition is true
What are the symbols used in if statements?
→ symbols used in if statement (comparison operators) → <, >, <=, >=, == (use double equal sign for equality evaluating NOT variable assignment
→ != means dosent equal
What is else?
→ else: a reserved python word in conditionals used when if statements are false
→ This else keyword line will run the code block underneath if the first condition is false
What are complex conditionals?
→ complex conditionals: when programs have more than one choice in their conditional statements
→ Some programs involve more than one or two choices and therefore more complexity. As previously stated, we call conditional statements that have more than one choice, complex conditionals.
What is elif?
→ elif: else if statement that makes conditions exclusive where one condition is tested at a time and once one condition is found to be true (code dosent test the rest)
What is the and operator?
→ the “and” operator is an if statement consisting of two conditions: both conditions must be met/made true in order for whole condition to be true
What is the or operator?
→ the “or” operator is where at least on of the two conditions in the if statement must be true in order to make whole condition true (both false is where the whole stsament is false)
What is the not operator?
→ the “not” operator is not the same as !=, it is like an inverter where teh first print ststament prints if false and one in else prints if true
What is conditional code?
→ We need to have code that sometimes runs, and sometimes doesn’t depending on the conditions of the program at that time. This is conditional code.
What is the general format of an if statement?
→ The general format of an if statement is as follows…
if(condition is true):
→ Run all the code that is indented under the conditional statement.
if a < 50:
print(str(a) + “ is less than 50”)
What does this check?
→ This conditional checks to see if a is less than 50
if a > 50:
print(str(a) + “ is greater than 50”)
What does this check?
→ This conditional checks to see if a is greater than 50
if a == 50:
print(str(a) + “ is equal to 50”)
What does this check?
→ This conditional checks to see if a is equal to 50
if a != 50:
print(str(a) + “ does not equal to 50”)
What does this check?
→ This conditional checks to see if a is not equal to 50
What is the difference between a condition and a conditional?
A condition is an expression that evaluates to either True or False.
It’s the test itself.
A conditional is a statement or structure in code that uses a condition to decide what to do. It’s the control flow statement (if, elif, else) that checks conditions and executes code accordingly.
Condition = the test (boolean expression, like x > 5).
Conditional = the structure that uses the test to control program flow (if, elif, else).
Condition = the question (“Is it raining?”).
Conditional = the decision-making structure (“If it’s raining, bring an umbrella, else wear sunglasses”).