Python Loops

Loops in Python are used to execute a block of code repeatedly, either for a specified number of times or while a condition is true. They help automate repetitive tasks and simplify code.

Last Updated :
Discuss
Comments

Question 1

In programming, what is an iteration?

  • The repetition of steps within a program.

  • The order in which instructions are carried out

  • A decision point in a program

  • Testing a program to make sure it works

Question 2

To solve a problem that requires the user to enter 10 numbers would use what type of iteration?

  • While loop

  • For loop

  • If

  • Else

Question 3

What will be the output of the following code?

d = {0, 1, 2}

for x in d:

    print(x)

  • 0 1 2

  • { 0, 1, 2} { 0, 1, 2}{ 0, 1, 2}

  • Error

  • No output

Question 4

What is the output of the following code?

True = False

while True:

     print(True)

     break

  • True

  • False

  • 1

  • None of the above

Question 5

What is the output of the following nested loop?

Python
n = [10, 20]
li = ["Chair", "Table"]
 
for x in n:
  for y in li:
      print(x, y)


  •  10 Chair

     10 Table

  • 10 Chair

    10 Table

    20 Chair

    20 Table

  • Error

  • No output

Question 6

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

Python
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)


  • 20

  • 10

  • 30

  • 14

Question 7

What is the output of the following nested loop?

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


  • 10

    11

    12

    13

  • 12

    14

  • Error

  • No output

Question 8

What is the output of the following code?

X=5;

while X>0:

      X=X-1;

      print(X)

  • 5  

    4  

    3  

    2  

    1  

    0

  • 4  

    3  

    2  

    1  

    0

  • 5  4  3  2  1

  • 4  3  2  1  0

Question 9

What is the value of x?

x = 0

while (x < 100):

    x+=2

print(x)

  • 101

  • 99

  • 98

  • 100

Question 10

The best command to repeat a control statement a fixed number of times?

  •  While loop

  • For loop

  • If

  • Else

There are 19 questions to complete.

Take a part in the ongoing discussion