Python Loops

Last Updated :
Discuss
Comments

Question 1

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

  • A

     While loop

  • B

    For loop

  • C

    If

  • D

    Else

Question 2

What will be the output of the following Python code?

Python
for i in range(int(2.0)):
   print(i)


  • A

    0.0 1.0

  • B

    0 1

  • C

    Error

  • D

    0
    1

Question 3

What will be the output of the following Python code?

Python
x = 'abcd'
for i in range(len(x)):  
    print(i, end= " ")
  • A

    1 2 3 4 

  • B

    0 1 2 3

  • C

    Error

  • D

    No output

Question 4

What will be the output of the following code? 

Python
x = "GFG"
for i in range(x):
    print(i)
  • A

    G F G

  • B

    0 1 2

  • C

    Error

  • D

    No output

Question 5

What is the output of the following code?

Python
while True:
  
	print(“Geeks!”)
  • A

    Geeks!

  • B

    “Geeks!”

  • C

    ‘Geeks!’

  • D

    Geeks!

    Geeks!

    Geeks!

    (Repeated infinite times)

Question 6

Which type of loop continues to iterate until explicitly instructed to stop?

  • A

    For loop

  • B

    While loop

  • C

    For-each loop

  • D

    None of the above

Question 7

Which two statements are used to implement iteration?

  • A

    IF and WHILE

  • B

    IF and FOR

  • C

    FOR and WHILE

  • D

    IF and ELSE

Question 8

The character that must be at the end of the line for if, while, for etc.

  • A

    :

  • B

    ;

  • C

    ,

  • D

    .

Question 9

What is the output of the following code?

Python
i = 1
while True:
   if i%7 == 0:
   	 break    
   print(i, end=" ")
   i += 1
  • A

    1 2 3 4 5 6 

  • B

    1 2 3 4 5 6 7

  • C

    No output

  • D

    Error

Question 10

What is the output of the following code?

Python
while True:
    print("Geeks!")
    break
  • A

    Geeks!

  • B

    “Geeks!”

  • C

    ‘Geeks!’

  • D

    Geeks!
    Geeks!
    Geeks!
    (Repeated infinite times)

There are 19 questions to complete.

Take a part in the ongoing discussion