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.
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?
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?
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?
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?
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 9
What is the output of the following code?
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?
while True:
print(“Geeks!”)
break;
Geeks!
“Geeks!”
‘Geeks!’
Geeks!
Geeks!
Geeks!
(Repeated infinite times)
There are 19 questions to complete.