1/31
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What are conditionals used for in Python?
To ask questions and make decisions based on the answers.
What Python keyword starts a conditional block?
if
What type of expression does an if statement use?
A Boolean expression (evaluates to True or False)
How do you write a basic if statement in Python?
if condition:
# code
What does the else keyword do in a conditional?
It defines code to run if the if condition is false.
How do you write an if-else statement in Python?
if condition:
# code
else:
# other code
What is a nested conditional?
An if or else statement inside another if or else.
Why use nested conditionals?
To check multiple, dependent conditions in sequence.
What does elif mean in Python?
“Else if” — checks another condition if the first is false.
How do you use elif in a conditional chain?
if cond1:
# code
elif cond2:
# other code
When should you use elif instead of multiple if statements?
When only one condition should be true and run.
Why is input validation important in conditionals?
To handle unexpected or invalid user inputs.
How do you provide feedback for invalid input?
print("Enter a valid option")
What happens if the user input doesn’t match any condition?
The program should inform the user and handle the input safely.
What is a Boolean expression?
A question that returns True or False.
What does == do in a condition?
Compares values for equality.
What does != do in a condition?
Checks if two values are not equal.
What does the or operator do?
Returns True if at least one condition is true.
Syntax example using or in Python?
if x == 1 or x == 2:
What does the and operator do?
Returns True only if both conditions are true.
Syntax example using and in Python?
if x == 1 and y == 2:
What does the not operator do?
Reverses the Boolean value (True becomes False).
Syntax example using not in Python?
if not valid:
How do you check for multiple valid options using or?
if difficulty == "Difficult" or difficulty == "Casual":
How do you validate invalid inputs using not?
if not (condition):
How do you combine conditions using and for accuracy?
if difficulty == "Difficult" and players == "Multiplayer":
How does Boolean logic improve readability?
It simplifies complex conditions into clear expressions.
How does Boolean logic reduce redundancy?
It replaces repeated or nested checks with concise logic.
How does Boolean logic help with input validation?
It enables checking for all valid or invalid options clearly.
Why is testing with valid and invalid inputs important?
To ensure the program handles all scenarios properly.
What should test cases for conditionals include?
All valid paths, all invalid inputs, and edge cases.
What is the goal of testing Boolean logic?
To confirm that each branch executes as expected.