Python Conditionals Test Flashcards

(16 cards)

1
Q

What is if?

A

→ 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

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

What is a code block?

A

→ code block: all code intended after if statement executed if condition is true

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

What are the symbols used in if statements?

A

→ symbols used in if statement (comparison operators) → <, >, <=, >=, == (use double equal sign for equality evaluating NOT variable assignment
→ != means dosent equal

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

What is else?

A

→ 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

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

What are complex conditionals?

A

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

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

What is elif?

A

→ 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)

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

What is the and operator?

A

→ 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

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

What is the or operator?

A

→ 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)

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

What is the not operator?

A

→ 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

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

What is conditional code?

A

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

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

What is the general format of an if statement?

A

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

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

if a < 50:
print(str(a) + “ is less than 50”)
What does this check?

A

→ This conditional checks to see if a is less than 50

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

if a > 50:
print(str(a) + “ is greater than 50”)
What does this check?

A

→ This conditional checks to see if a is greater than 50

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

if a == 50:
print(str(a) + “ is equal to 50”)
What does this check?

A

→ This conditional checks to see if a is equal to 50

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

if a != 50:
print(str(a) + “ does not equal to 50”)
What does this check?

A

→ This conditional checks to see if a is not equal to 50

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

What is the difference between a condition and a conditional?

A

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