Computer Science

Python Loops MCQs | 25 Practice Questions with Answers | CBSE Class 11 Computer Science

Class 11 · Computer Science

Python Loops MCQs (25 Questions)

Practice these multiple-choice questions to strengthen your understanding of Python Loops. Click Show Answer to reveal the correct answer and explanation.


Q1. Which looping statement is used to repeat a block of code a fixed number of times?

A. if
B. while
C. for
D. switch

Show Answer

Answer: C. for

Explanation: A for loop is generally used when the number of iterations is known.


Q2. Which loop continues execution until a given condition becomes False?

A. for
B. while
C. if
D. break

Show Answer

Answer: B. while

Explanation: A while loop executes repeatedly as long as its condition evaluates to True.


Q3. Which function is commonly used with a for loop to generate a sequence of numbers?

A. list()
B. range()
C. len()
D. random()

Show Answer

Answer: B. range()

Explanation: The range() function generates a sequence of numbers for iteration.


Q4. What is the output of the following code?

for i in range(5):
    print(i,end=" ")

A. 1 2 3 4 5
B. 0 1 2 3 4
C. 0 1 2 3 4 5
D. 5 4 3 2 1

Show Answer

Answer: B. 0 1 2 3 4

Explanation: range(5) generates numbers from 0 to 4.


Q5. Which statement immediately terminates the loop?

A. continue
B. stop
C. break
D. exit

Show Answer

Answer: C. break

Explanation: The break statement immediately exits the nearest enclosing loop.


Q6. Which statement skips the current iteration and continues with the next iteration?

A. break
B. continue
C. pass
D. stop

Show Answer

Answer: B. continue

Explanation: The continue statement skips the remaining statements in the current iteration.


Q7. Which loop is most suitable when the number of iterations is unknown?

A. for
B. while
C. nested loop
D. infinite loop

Show Answer

Answer: B. while

Explanation: A while loop is used when the number of iterations depends on a condition.


Q8. Which of the following is the correct syntax for a for loop?

A. for(i=0;i<5;i++)
B. for i in range(5):
C. for(i in 5)
D. loop i=1 to 5

Show Answer

Answer: B. for i in range(5):

Explanation: This is the correct Python syntax for a for loop.


Q9. What is the output of the following code?

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

A. 2 3 4 5
B. 1 2 3 4 5
C. 2 3 4 5 6
D. 3 4 5

Show Answer

Answer: A. 2 3 4 5

Explanation: The starting value is included, while the ending value is excluded.


Q10. Which argument of range() specifies the increment or decrement?

A. start
B. stop
C. step
D. index

Show Answer

Answer: C. step

Explanation: The third argument of range() specifies the step value.


Q11. What is the output of the following code?

for i in range(1,10,2):
    print(i,end=" ")

A. 1 3 5 7 9
B. 1 2 3 4 5
C. 2 4 6 8
D. 0 2 4 6 8

Show Answer

Answer: A. 1 3 5 7 9

Explanation: The third argument (2) specifies the step value, so only odd numbers are generated.


Q12. What is the output of the following code?

for i in range(5,0,-1):
    print(i,end=" ")

A. 1 2 3 4 5
B. 5 4 3 2 1
C. 5 4 3 2
D. 4 3 2 1

Show Answer

Answer: B. 5 4 3 2 1

Explanation: A negative step generates numbers in descending order.


Q13. What is a nested loop?

A. A loop without a condition.
B. A loop inside another loop.
C. A loop that never ends.
D. A loop using the break statement.

Show Answer

Answer: B. A loop inside another loop.

Explanation: A nested loop is a loop placed inside another loop.


Q14. Which statement is true about nested loops?

A. The inner loop completes all its iterations for each iteration of the outer loop.
B. The outer loop executes only once.
C. Nested loops are not allowed in Python.
D. Only while loops can be nested.

Show Answer

Answer: A.

Explanation: For every iteration of the outer loop, the inner loop executes completely.


Q15. Which of the following can create an infinite loop?

A. while True:
B. for i in range(5):
C. for i in range(1):
D. while False:

Show Answer

Answer: A.

Explanation: Since the condition is always True, the loop continues indefinitely unless terminated using break.


Q16. What is the output of the following code?

for i in range(5):
    if i==3:
        break
    print(i,end=" ")

A. 0 1 2
B. 0 1 2 3 4
C. 1 2 3
D. 0 1 2 4

Show Answer

Answer: A. 0 1 2

Explanation: The loop terminates when i becomes 3.


Q17. What is the output of the following code?

for i in range(5):
    if i==2:
        continue
    print(i,end=" ")

A. 0 1 2 3 4
B. 0 1 3 4
C. 2 3 4
D. 0 1 2

Show Answer

Answer: B. 0 1 3 4

Explanation: The continue statement skips the iteration when i is 2.


Q18. Which loop is generally preferred for traversing a list or a string?

A. while loop
B. do-while loop
C. for loop
D. switch loop

Show Answer

Answer: C. for loop

Explanation: A for loop is the preferred choice for traversing sequences such as lists and strings.


Q19. Which loop is generally used for pattern printing in Python?

A. Only while loop
B. Nested loops
C. Only if statement
D. switch statement

Show Answer

Answer: B. Nested loops

Explanation: Pattern printing usually requires nested loops, where the outer loop controls rows and the inner loop controls columns.


Q20. Which statement is correct about the range() function?

A. The stop value is included.
B. The stop value is excluded.
C. The start value is excluded.
D. It always generates floating-point numbers.

Show Answer

Answer: B. The stop value is excluded.

Explanation: The range() function includes the start value but excludes the stop value.


Q21. Which loop is most suitable for calculating the factorial of a number?

A. if statement
B. for loop
C. switch statement
D. pass statement

Show Answer

Answer: B. for loop

Explanation: A for loop is commonly used to calculate the factorial of a number because the number of iterations is known.


Q22. Which loop is commonly used to generate star (*) patterns in Python?

A. if statement
B. while loop only
C. Nested loops
D. switch statement

Show Answer

Answer: C. Nested loops

Explanation: Pattern printing requires nested loops where the outer loop controls rows and the inner loop controls columns.


Q23. What is the output of the following code?

i=1
while i<=3:
    print(i,end=" ")
    i=i+1

A. 0 1 2
B. 1 2 3
C. 1 2 3 4
D. Infinite Loop

Show Answer

Answer: B. 1 2 3

Explanation: The value of i starts from 1 and increases by 1 until it becomes greater than 3.


Q24. What is the output of the following code?

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

A.

**
**
**

B.

***
***
***

C.

**
**

D.

* *
* *
* *
Show Answer

Answer: A.

Explanation: The outer loop executes three times, while the inner loop prints two stars during each iteration.


Q25. Which of the following is the best real-life application of loops?

A. Repeating calculations for multiple students' marks
B. Declaring variables
C. Importing modules
D. Creating dictionaries only

Show Answer

Answer: A. Repeating calculations for multiple students' marks

Explanation: Loops are used whenever a task needs to be repeated multiple times, such as processing marks, salaries, attendance, or records.


Answer Key

Q.No. Answer Q.No. Answer Q.No. Answer
1C 10C 19B
2B 11A 20B
3B 12B 21B
4B 13B 22C
5C 14A 23B
6B 15A 24A
7B 16A 25A
8B 17B
9A 18C

Practice Tips

  • Understand the difference between for and while loops.
  • Remember that range(start, stop, step) includes the start value but excludes the stop value.
  • Practice output-based questions using break and continue.
  • Learn how nested loops are used for pattern printing and table generation.
  • Practice programs on factorial, summation of series, multiplication tables, and pattern printing.
  • Attempt the MCQs without viewing the answers first, then use the explanations to strengthen your understanding.