1/19
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What does the print() function do in Python?
It displays output to the screen.
What is a variable?
A named storage location for data that can change during program execution.
What is the difference between = and == in Python?
= assigns a value, while == checks equality.
What does the input() function do?
It lets the user type input, which is read as a string.
What is the basic syntax for an if-else statement that executes different code based on a condition?
if condition:\n # code executes if condition is True\nelse:\n # code executes if condition is False\nKey point: Only one branch executes.
How do you trace through code with conditionals to find final variable values?
Start with initial values, evaluate conditions in order, execute only the block that's true, skip the rest, continue after conditionals, and update variables step by step.
What's the difference between an if-elif-else chain and multiple separate if statements?
An if-elif-else chain only runs the first true condition and then exits. Multiple if statements check independently, so more than one block can run.
What are the key comparison operators and how do they evaluate?
== equal to, != not equal to, < less than, <= less than or equal to, > greater than, >= greater than or equal to. They return True or False.
In what order are operators evaluated in expressions like x + y < z * 2?
Parentheses → Multiplication/Division → Addition/Subtraction → Comparisons → Logical operators. Example: (x + y) < (z * 2).
How do nested if statements work, and what conditions must be true for inner blocks to execute?
The outer condition must be True, and the inner condition must also be True for the inner block to run.
How do you check if a value exists in a list, dictionary, or string?
Use membership operators: value in container (True if found), value not in container (True if not found).
How do you create conditions that check if a value falls within a specific range?
Use two conditions with and. Example: if x >= 10 and x <= 20:
When does variable assignment inside conditional blocks take effect?
Only when that block runs. If the condition is False, the assignment is skipped.
What are the essential indentation rules for conditionals in Python?
Code in if/else must be indented, all code at the same level has the same indent, else lines up with if, and code after conditionals goes back to the left margin.
How do you determine which branch of a multi-way conditional will execute?
In an if-elif-else chain, Python checks from top to bottom. The first True condition executes, and the rest are skipped. If none are True, the else block runs.
What's the strategy for creating complex conditions with multiple requirements?
Use compound logic: and = all must be true, or = any can be true, not = reverses condition. Parentheses group conditions for clarity.
What's the systematic approach to debug conditional statements that aren't working as expected?
Check variable values, trace condition evaluation, verify operator precedence, check indentation, test edge cases, and use print statements to confirm values.
What are membership operators in Python?
in and not in, used to test whether a value exists in a list, string, or dictionary.
What are identity operators in Python?
is and is not, used to check whether two objects are the same type or reference.
What are nested if statements?
An if statement inside another if, creating multiple levels of decision-making.