PYnative

Python Programming

  • Learn Python
  • Exercises
  • Quizzes
  • Code Editor
  • Tricks
Home » Python » Quizzes » Python Flow Control ( If Else and Loops) Quiz

Python Flow Control ( If Else and Loops) Quiz

Updated on: August 24, 2022 | 35 Comments

This Python Flow Control ( If Else and Loops) Quiz quiz provides Multiple Choice Questions(MCQ) to get familiar with if-else conditions, for loop, and while loop. This online quiz will help you to improve your understanding of branching and Looping techniques in Python.

Also, Solve Python if-else, for loop, and range() Exercise.

  • The quiz contains 13 Questions. Solve 8 correct to pass the test.
  • You will have to read all the given answers and click over the correct answer.

Read the following tutorials to solve this quiz

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

1. Given the nested if-else structure below, what will be the value of x after code execution completes

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)
 
 
 
 

2. What is the output of the following loop

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

3. What is the value of x

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

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

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

5. What is the output of the following for loop and  range() function

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

6. 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)
 
 

7. What is the value of x after the following nested for loop completes its execution

x = 0
for i in range(10):
  for j in range(-1, -10, -1):
    x += 1
    print(x)
 
 
 

8. Select which is true for for loop

 
 
 
 

9. What is the value of the var after the for loop completes its execution

var = 10
for i in range(10):
    for j in range(2, 10, 1):
        if var % 2 == 0:
            continue
            var += 1
    var+=1
else:
    var+=1
print(var)
 
 
 
 

10. if -3 will evaluate to True

 
 

11. What is the output of the following if statement

a, b = 12, 5
if a + b:
    print('True')
else:
  print('False')
 
 

12. Given the nested if-else below, what will be the value x when the code executed successfully

x = 0
a = 5
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)
 
 
 
 

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

for num in range(10, 14):
   for i in range(2, num):
       if num%i == 1:
          print(num)
          break

Hint:

  • Nested loop in Python
  • Break and continue in Python
 
 

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

Founder of PYnative.com I am a Python developer and I love to write articles to help developers. Follow me on Twitter. All the best for your future Python endeavors!

Related Tutorial Topics:

Python Python Basics Python Quizzes

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 10 questions
  • Each Quiz contains 12-15 MCQ
Exercises
Quizzes

Posted In

Python Python Basics Python Quizzes
TweetF  sharein  shareP  Pin

  Python Quizzes

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

All Python Topics

Python Basics Python Exercises Python Quizzes 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.

Explore Python

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

Follow Us

To get New Python Tutorials, Exercises, and Quizzes

  • Twitter
  • Facebook
  • Sitemap

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, Cookie Policy, and Privacy Policy.

Copyright © 2018–2023 pynative.com