Python Loops

    Last Updated :
    Discuss
    Comments

    Question 1

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

    •  While loop

    • For loop

    • If

    • Else

    Question 2

    What will be the output of the following Python code?

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


    • 0.0 1.0

    • 0 1

    • Error

    • 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= " ")
    
    • 1 2 3 4 

    • 0 1 2 3

    • Error

    • No output

    Question 4

    What will be the output of the following code? 

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

    • 0 1 2

    • Error

    • No output

    Question 5

    What is the output of the following code?

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

    • “Geeks!”

    • ‘Geeks!’

    • Geeks!

      Geeks!

      Geeks!

      (Repeated infinite times)

    Question 6

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

    • For loop

    • While loop

    • For-each loop

    • None of the above

    Question 7

    Which two statements are used to implement iteration?

    • IF and WHILE

    • IF and FOR

    • FOR and WHILE

    • IF and ELSE

    Question 8

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

    • :

    • ;

    • ,

    • .

    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
    
    • 1 2 3 4 5 6 

    • 1 2 3 4 5 6 7

    • No output

    • Error

    Question 10

    What is the output of the following code?

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

    • “Geeks!”

    • ‘Geeks!’

    • Geeks!
      Geeks!
      Geeks!
      (Repeated infinite times)

    There are 19 questions to complete.

    Take a part in the ongoing discussion