Vidyalelo
Python · all questions

Python Loops and Conditionals: MCQs for Exam Readiness
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

91

Questions

2/5

Page

Pick an option on a question to see the right answer and solution.

What is the purpose of the continue statement in loops?

Select an option to see the answer and solution.

What is the output of the following code snippet:
for i in range(3, 0, -1):
    print(i)

Select an option to see the answer and solution.

In Python, which loop is commonly used when you have a specific condition to break the loop?

Select an option to see the answer and solution.

What will the following code print:
x = 5
while x > 0:
    print(x)
    x -= 1

Select an option to see the answer and solution.

What is the output of the following code:
x = 0
while x < 5:
    print(x)
    x += 1

Select an option to see the answer and solution.

What is the purpose of the pass statement in a loop?

Select an option to see the answer and solution.

In Python, which loop is suitable for cases where you need to execute a block of code multiple times until a condition is met?

Select an option to see the answer and solution.

What is the output of the following code snippet:
for i in range(1, 5, 2):
    print(i)

Select an option to see the answer and solution.

What will the following loop print:
for i in range(3):
    print(i)

Select an option to see the answer and solution.

What is the output of the following code snippet:
count = 0
while count < 3:
    print("Hello")
    count += 1

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
a = [0, 1, 2, 3]
for a[0] in a:
    print(a[0])

Select an option to see the answer and solution.

What will be the output of the following Python code?
for i in range(5):
    if i == 5:
        break
    else:
        print(i)
else:
    print("Here")

Select an option to see the answer and solution.

What will be the output of the following Python code?
for i in range(10):
    if i == 5:
        break
    else:
        print(i)
else:
    print("Here")

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
string = "my name is x"
for i in ' '.join(string.split()):
    print (i, end=", ")

Select an option to see the answer and solution.

What will be the output of the following Python code?
x = (i for i in range(3))
for i in x:
    print(i)
for i in x:
    print(i)

Select an option to see the answer and solution.

What will be the output of the following Python code?
string = "my name is x"
for i in string:
    print (i, end=", ")

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
a = [0, 1, 2, 3]
for a[-1] in a:
    print(a[-1])

Select an option to see the answer and solution.

What will be the output of the following Python code?
x = (i for i in range(3))
for i in x:
    print(i)

Select an option to see the answer and solution.

What will be the output of the following Python code?
string = "my name is x"
for i in string.split():
    print (i, end=", ")

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
a = [0, 1, 2, 3]
i = -2
for i not in a:
    print(i)
    i += 1

Select an option to see the answer and solution.