What is a for loop used for in Python?

Python Loop Quiz

Quiz
•
Other
•
12th Grade
•
Hard
ruth sutton
Used 1+ times
FREE Resource
20 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
To execute a block of code indefinitely
To iterate over a sequence
To evaluate conditions only
To terminate a program
Answer explanation
A for loop in Python is specifically designed to iterate over a sequence, such as a list, tuple, or string, allowing you to execute a block of code for each item in that sequence.
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the output of the following code? python Copy code for i in range(3): print(i)
1 2 3
0 1 2
0 1 2 3
None
Answer explanation
The code uses a for loop with range(3), which generates numbers starting from 0 up to, but not including, 3. Therefore, the output will be 0, 1, and 2, making the correct answer '0 1 2'.
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What keyword is used to stop a while loop in Python?
exit
stop
break
continue
Answer explanation
In Python, the keyword 'break' is used to exit a while loop prematurely. The other options, 'exit', 'stop', and 'continue', do not serve this purpose. 'Continue' actually skips to the next iteration of the loop.
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
How many times will this loop run? python Copy code count = 0 while count < 5: count += 1
4
5
Infinite
6
Answer explanation
The loop starts with count = 0 and increments count by 1 each iteration. It runs while count is less than 5. Therefore, it will run 5 times (count = 1 to 5) before exiting, making the correct answer 5.
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What does range(5) generate?
1 to 5
0 to 5
0 to 4
Infinite values
Answer explanation
The function range(5) generates a sequence of numbers starting from 0 up to, but not including, 5. Therefore, it produces the values 0, 1, 2, 3, and 4, making the correct answer 0 to 4.
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What does the continue keyword do in a loop?
Stops the loop completely
Skips the current iteration and continues to the next
Repeats the current iteration
Breaks the loop
Answer explanation
The continue keyword in a loop skips the current iteration when encountered and proceeds to the next iteration. This allows the loop to continue running without executing the remaining code in the current iteration.
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What will this code output? python Copy code for i in range(4): if i == 2: continue print(i)
0 1 2 3
0 1 3
1 3
None
Answer explanation
The loop iterates from 0 to 3. When i is 2, the 'continue' statement skips the print. Thus, the output is 0, 1, and 3, making the correct answer '0 1 3'.
Create a free account and access millions of resources
Similar Resources on Quizizz
25 questions
Arduino BOE Bot MS

Quiz
•
9th - 12th Grade
21 questions
Turtle Graphics and Range in Python

Quiz
•
12th Grade
24 questions
Karel in Python Quiz Practice

Quiz
•
12th Grade
17 questions
Python Ranges and Operators

Quiz
•
12th Grade
16 questions
Python

Quiz
•
9th - 12th Grade
20 questions
Mastering Python Loops Quiz

Quiz
•
12th Grade
15 questions
Python Quiz

Quiz
•
12th Grade
20 questions
Trắc nghiệm lần 2 - K10

Quiz
•
10th Grade - University
Popular Resources on Quizizz
15 questions
Multiplication Facts

Quiz
•
4th Grade
25 questions
SS Combined Advisory Quiz

Quiz
•
6th - 8th Grade
40 questions
Week 4 Student In Class Practice Set

Quiz
•
9th - 12th Grade
40 questions
SOL: ILE DNA Tech, Gen, Evol 2025

Quiz
•
9th - 12th Grade
20 questions
NC Universities (R2H)

Quiz
•
9th - 12th Grade
15 questions
June Review Quiz

Quiz
•
Professional Development
20 questions
Congruent and Similar Triangles

Quiz
•
8th Grade
25 questions
Triangle Inequalities

Quiz
•
10th - 12th Grade
Discover more resources for Other
40 questions
Week 4 Student In Class Practice Set

Quiz
•
9th - 12th Grade
40 questions
SOL: ILE DNA Tech, Gen, Evol 2025

Quiz
•
9th - 12th Grade
20 questions
NC Universities (R2H)

Quiz
•
9th - 12th Grade
25 questions
Triangle Inequalities

Quiz
•
10th - 12th Grade
65 questions
MegaQuiz v2 2025

Quiz
•
9th - 12th Grade
10 questions
GPA Lesson

Lesson
•
9th - 12th Grade
15 questions
SMART Goals

Quiz
•
8th - 12th Grade
45 questions
Week 3.5 Review: Set 1

Quiz
•
9th - 12th Grade