
Iteration in Python Quiz
Authored by Andrew Asante
Computers
12th Grade
Used 5+ times

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
9 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
1. Write a Python program to display all the prime numbers within a range using a for loop.
for num in range(lower, upper + 1): if num > 1: for i in range(2, num): if (num % i) == 0: break else: print(num)
for num in range(1, upper + 1): if num > 1: for i in range(2, num): if (num % i) == 0: break else: print(num)
for num in range(upper, lower - 1, -1): if num > 1: for i in range(2, num): if (num % i) == 0: break else: print(num)
for num in range(lower, upper + 1): if num > 1: for i in range(2, num + 1): if (num % i) == 0: break else: print(num)
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
2. How does a for loop work in Python? Provide an example.
A for loop in Python can only iterate over a list
The correct answer for the question is: A for loop in Python iterates over a sequence or iterable object, executing a block of code for each item in the sequence.
A for loop in Python only works with integers
A for loop in Python executes the block of code only once
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
3. Create a Python program to print the Fibonacci sequence using a while loop.
Print the prime numbers using a do-while loop
Print the Fibonacci sequence using a for loop
Print the factorial sequence using a while loop
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
5. Write a Python program to display the multiplication table using nested loops.
print('Multiplication table')
for i in range(1, 11):
for j in range(1, 11):
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
6. What are nested loops in Python? Provide an example.
Nested loops are loops that only run once
Nested loops are loops that cannot be used in Python
Nested loops are loops that run in parallel
Nested loops in Python are loops within a loop. They are used to iterate over multiple sequences or perform repetitive tasks. For example: for i in range(3): for j in range(2): print(i, j)
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
7. Write a Python program to iterate through a list and display the elements.
print(my_list)
while my_list: print(my_list.pop())
for i in range(len(my_list)): print(my_list[i])
for item in my_list: print(item)
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
8. Explain how to iterate through a list in Python with an example.
for i in range(len(my_list)): print(my_list[i])
while item in my_list: print(item)
if item in my_list: print(item)
for item in my_list: print(item)
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
10 questions
BTEC National U2 - Testing Tables (Paper - Part A)
Quiz
•
12th Grade
10 questions
Prog. no Des. de Sistemas - Classes e Objetos em python
Quiz
•
12th Grade
10 questions
Arduino X-3
Quiz
•
9th - 12th Grade
10 questions
Списки Python + Pygame
Quiz
•
KG - University
12 questions
1.2.4. Types of Programming Language
Quiz
•
12th Grade
11 questions
Types of Mass Media
Quiz
•
10th Grade - Professi...
13 questions
Programming Concepts Quiz
Quiz
•
6th Grade - University
10 questions
BTEC National ICT U2 - Microsoft Access
Quiz
•
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