What is a control structure?
The logical design that controls the order in which statements execute
What is a sequence structure?
A set of statements that execute in the order they appear
What is a decision (selection) structure?
A structure where specific actions are performed only if a condition exists
What is the syntax of an if statement in Python?
if condition:
statement(s)
The condition is tested; if true, the block executes; otherwise, it is skipped
What is a Boolean expression?
An expression that evaluates to either True or False
What are relational operators in Python?
> , <, >=, <=, ==, !=
What is the difference between = and == in Python?
= is the assignment operator; == tests for equality
What is a single-line if statement?
A condensed form where one statement executes if the condition is true (e.g., if score > 59: print(‘You passed!’))
What is an if-else statement?
A dual alternative decision structure with one path if the condition is true and another if false
How are strings compared in Python?
Using ==, !=, <, >, <=, >=; comparisons are case-sensitive and based on ASCII values
What is a nested decision structure?
An if statement inside another if statement
What is the if-elif-else statement used for?
To simplify nested decision structures and allow multiple conditions
What are logical operators in Python?
and, or, and not
When is and true?
Only when both sub-expressions are true
When is or true?
When at least one sub-expression is true
What does not do?
Reverses the truth value of its operand
What is short-circuit evaluation?
Evaluating a compound Boolean expression by stopping once the outcome is known (e.g., in or, if the left side is true, Python skips the right)
How do you check numeric ranges with logical operators?
Inside range: x >= 10 and x <= 20
Outside range: x < 10 or x > 20
What is a Boolean variable?
A variable referencing either True or False, often used as a flag
What is a flag variable?
A Boolean variable that signals when a condition exists in a program
What is a conditional expression in Python?
A shorthand if-else expression: value1 if condition else value2
Example of a conditional expression?
grade = ‘Pass’ if score > 59 else ‘Fail’
What is the walrus operator (:=)
An enhanced assignment operator that both assigns a value and returns it
Example of walrus operator usage?
if (area := width * height) > 100: print(‘The area is too large’)