
Python Loop Quiz
Authored by ruth sutton
Other
12th Grade
Used 1+ times

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
20 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is a for loop used for in Python?
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'.
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?
Similar Resources on Wayground
15 questions
Teori Muzik | Tahun 4
Quiz
•
4th Grade - University
20 questions
KUIZ BUKU REKOD PENGAWASAN PEPERIKSAAN SPM 2022
Quiz
•
12th Grade
15 questions
Chayamana Quiz Competition
Quiz
•
1st Grade - University
20 questions
Goat and sheep housing
Quiz
•
12th Grade
20 questions
Quiz de villanos en el cine
Quiz
•
KG - Professional Dev...
15 questions
Лекция 1. Шахматные правила
Quiz
•
KG - Professional Dev...
20 questions
ELEKTRONIK DIGITAL
Quiz
•
9th - 12th Grade
15 questions
QUIZ SURAT LAMARAN PEKERJAAN
Quiz
•
9th - 12th Grade
Popular Resources on Wayground
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
22 questions
fractions
Quiz
•
3rd Grade
20 questions
Main Idea and Details
Quiz
•
5th Grade
20 questions
Context Clues
Quiz
•
6th Grade
15 questions
Equivalent Fractions
Quiz
•
4th Grade
20 questions
Figurative Language Review
Quiz
•
6th Grade
Discover more resources for Other
20 questions
-AR -ER -IR present tense
Quiz
•
10th - 12th Grade
12 questions
Add and Subtract Polynomials
Quiz
•
9th - 12th Grade
13 questions
Model Exponential Growth and Decay Scenarios
Quiz
•
9th - 12th Grade
27 questions
7.2.3 Quadrilateral Properties
Quiz
•
9th - 12th Grade
7 questions
Amoeba Sisters Dihybrid Cross Punnett Square
Interactive video
•
9th - 12th Grade
10 questions
The Holocaust: Historical Overview
Interactive video
•
9th - 12th Grade
10 questions
Key Features of Quadratic Functions
Interactive video
•
8th - 12th Grade
11 questions
Exponent Quotient Rules A1 U7
Quiz
•
9th - 12th Grade