Python Conditional Statements Quiz
Welcome to the Python Control Flow (Conditional Statements) Quiz!
In Python, control flow (conditional statements) provides logical structure of decision making. The quiz will test your understanding of if, elif, else, and other control flow concepts in Python.
Each question is designed to strengthen your problem-solving skills. Let’s see how well you know Python’s decision-making structures!
Table of Contents:
- Python quizzes for beginners series
- Python Variables and Data Types Quiz
- Python Operators Quiz
- Python Control Flow (Conditional Statements) Quiz
- Python Loops Quiz
- Python Functions Quiz
- Python Lists Quiz
- Python Dictionaries Quiz
- Python Tuples Quiz
- Python Sets Quiz
- Python File Handling Quiz
Conditional Statements Quiz
Quiz Questions:
1. What will be the output of the following code?
if x > 5:
print("Greater")
else
print("Smaller")
Answer
Greater
2. What keyword is used for a conditional statement in Python?
Answer
if
3. What will be printed?
num = 7
if num % 2 == 0:
print("Even")
else:
print("Odd")
Answer
Odd
4. What does elif
stand for?
Answer
else if
5. What will be the output?
x = 20
if x < 10:
print("Low")
elif x < 30:
print("Medium")
else:
print("High")
Answer
Medium
6. Can you use multiple elif
statements in an if-elif-else structure?
Answer
Yes
7. What will be printed?
x = 15
if x > 10:
if x < 20:
print("Between 10 and 20")
Answer
Between 10 and 20
8. What happens if no condition in an if-elif-else chain is true?
Answer
If there’s an else
, it executes. Otherwise, nothing happens.
9. What will be the output?
x = 5
y = 10
if x > y:
print("X is greater")
elif x < y:
print("Y is greater")
else:
print("Equal")
Answer
Y is greater
10. What type of values do conditional expressions evaluate to?
Answer
Boolean (True
or False
)
11. What will be printed?
x = 3
if x:
print("True")
else:
print("False")
Answer
True
(because 3
is truthy)
12. What is the correct syntax for an if
statement?
Answer
if condition:
statement
13. What will be printed?
a = 0
if not a:
print("Zero")
Answer
Zero
14. What will be the output?
x = 100
if x > 50 and x < 200:
print("Valid")
Answer
Valid
15. What is the result of this expression?
if 0:
print("Yes")
else:
print("No")
Answer
No
(because 0
is falsy)
16. What happens if we write an if
condition without indentation?
Answer
IndentationError (Python requires indentation for code blocks)
17. What will be printed?
x = 20
if x == 10 or x == 20:
print("Match")
Answer
Match
18. How do you check if a number is negative?
Answer
if num < 0:
print("Negative")
19. What will be printed?
x = 5
y = 10
if x and y:
print("Both True")
Answer
Both True
(since both x
and y
are truthy)
20. What will be the output?
x = None
if x:
print("Value exists")
else:
print("No value")
Answer
No value
(because None
is falsy)
How did you do? 🎯
- 18-20 correct → 🏆 Excellent! You’re a Python functions pro!
- 14-17 correct → 👍 Great job! Keep practicing.
- 10-13 correct → 🙂 Good, but there’s room for improvement.
- Below 10 → 🤔 No worries! Review the concepts and try again.