PYnative

Python Programming

  • Learn Python
    • Python Tutorials
    • Python Basics
    • Python Interview Q&As
  • Exercises
  • Quizzes
  • Code Editor
Home » Python » Quizzes » Python Flow Control ( If Else and Loops) Quiz

Python Flow Control ( If Else and Loops) Quiz

Updated on: August 26, 2025 | 46 Comments

This Python loops and control flow (if-else and loops) Quiz provides Multiple Choice Questions (MCQ) to help you get familiar with if-else conditions, for loops, and while loops and also improve your understanding of branching and looping techniques in Python.

Also, See:

  • Python loops Exercise
  • 15 Python Quizzes: each focusing on a specific topic
  • The quiz contains 25 questions. There is no time limit.
  • You will get 1 point for each correct answer. Solve 15 correctly to pass the test.

Read the following tutorials to solve this quiz

  • Control flow statements
  • for loop
  • range() function
  • while loop
  • Break and Continue statement
  • Nested loop

1. In the expression condition1 and condition2, when is condition2 evaluated?

 
 
 
 

2. Which keyword is used to skip the rest of the current iteration of a loop and move to the next iteration?

 
 
 
 

3. Which of these is NOT a valid control flow statement in Python?

 
 
 
 

4. What is the purpose of the pass statement in Python?

 
 
 
 

5. What will be the output of the following Python code?

sum_val = 0 
for i in range(1, 4): 
  for j in range(1, 3): 
    sum_val += 1 
print(sum_val)
 
 
 
 

6. What will be the output of the following Python code?

matrix = [[1, 2], [3, 4]]
for row in matrix:
    for item in row:
        print(item, end=" ")
print()
 
 
 
 

7. What will be the output of the following Python code?

count = 0
while count < 5:
    print(count)
    if count == 2:
        break
    count += 1
else:
    print("Loop completed")
 
 
 
 

8. Given the nested if-else structure below, what will be the value of x

x = 0
a = 0
b = -5
if a > 0:
    if b < 0: 
        x = x + 5 
    elif a > 5:
        x = x + 4
    else:
        x = x + 3
else:
    x = x + 2
print(x)
 
 
 
 

9. What kind of error is most likely to occur if you incorrectly indent a line of code within an if block?

 
 
 
 

10. Consider the following code: my_list = [10, 20, 30]

Which of the following for loop correctly iterates through my_list and prints each element?

 
 
 
 

11. What is the output of the following loop

for i in 'Jhon':
   if i == 'o':
      pass
   print(i, end=", ")
 
 

12. What does the zip() function do when used with loops?

 
 
 
 

13. Which of the following conditions would most likely result in an infinite while loop?

 
 
 
 

14. When is the else block of a while loop executed?

 
 
 
 

15. When you iterate directly over a dictionary using a for loop (e.g., for key in my_dict:), what do you get in each iteration?

 
 
 
 

16. What is the output of the following range() function

for num in range(2,-5,-1):
    print(num, end=", ")
 
 
 

17. What will be the output of the following Python code?

for i in range(3):
  print(i * 2, end=" ")
 
 
 
 

18. What is the output of the following nested loop?

numbers = [10, 20]
items = ["Chair", "Table"]

for x in numbers:
  for y in items:
    print(x, y)
 
 

19. if -3 will evaluate to True

 
 

20. Which of the following correctly describes a while loop?

 
 
 

21. What will be the output of the following Python code?

nums = [10, 20, 30]
for num in nums:
    if num > 25:
        print("Large number found")
        break
else:
    print("No large numbers")
 
 
 
 

22. What sequence of numbers does range(1, 5) generate?

 
 
 
 

23. Which of the following statements is used to exit a loop prematurely in Python?

 
 
 
 

24. What will be the output of the following Python code?

data = ["apple", "banana", "cherry"]
for index, item in enumerate(data):
    print(f"{index}: {item}")
 
 
 
 

25. What is the value of x

x = 0
while x < 10:
  x+=2
print(x)
 
 
 
 

Loading ... Loading …

Loading

Filed Under: Python, Python Basics, Python Quizzes

Did you find this page helpful? Let others know about it. Sharing helps me continue to create free Python resources.

TweetF  sharein  shareP  Pin

About Vishal

Image

I’m Vishal Hule, the Founder of PYnative.com. As a Python developer, I enjoy assisting students, developers, and learners. Follow me on Twitter.

Related Tutorial Topics:

Python Python Basics Python Quizzes

All Coding Exercises:

C Exercises
C++ Exercises
Python Exercises

Python Exercises and Quizzes

Free coding exercises and quizzes cover Python basics, data structure, data analytics, and more.

  • 15+ Topic-specific Exercises and Quizzes
  • Each Exercise contains 25+ questions
  • Each Quiz contains 25 MCQ
Exercises
Quizzes

Loading comments... Please wait.

In: Python Python Basics Python Quizzes
TweetF  sharein  shareP  Pin

  Python Quizzes

  • 15 Python Quizzes
  • Python Online MCQ Test
  • Basic Quiz For Beginners
  • Variables and Data Types Quiz
  • Functions Quiz
  • if else and loops Quiz
  • Numbers Quiz
  • String Quiz
  • List Quiz
  • Set Quiz
  • Dictionary Quiz
  • Tuple Quiz
  • Operators and Expression Quiz
  • Input and Output Quiz
  • Multithreading and Multiprocessing Quiz
  • File Handling Quiz
  • Random Data Generation Quiz

 Explore Python

  • Python Tutorials
  • Python Exercises
  • Python Quizzes
  • Python Interview Q&A
  • Python Programs

All Python Topics

Python Basics Python Exercises Python Quizzes Python Interview Python File Handling Python OOP Python Date and Time Python Random Python Regex Python Pandas Python Databases Python MySQL Python PostgreSQL Python SQLite Python JSON

About PYnative

PYnative.com is for Python lovers. Here, You can get Tutorials, Exercises, and Quizzes to practice and improve your Python skills.

Follow Us

To get New Python Tutorials, Exercises, and Quizzes

  • Twitter
  • Facebook
  • Sitemap

Explore Python

  • Learn Python
  • Python Basics
  • Python Databases
  • Python Exercises
  • Python Quizzes
  • Online Python Code Editor
  • Python Tricks

Coding Exercises

  • C Exercises
  • C++ Exercises
  • Python Exercises

Legal Stuff

  • About Us
  • Contact Us

We use cookies to improve your experience. While using PYnative, you agree to have read and accepted our:

  • Terms Of Use
  • Privacy Policy
  • Cookie Policy

Copyright © 2018–2025 pynative.com

Advertisement