
Iteration in Python Quiz
Quiz
•
Computers
•
12th Grade
•
Practice Problem
•
Hard
Andrew Asante
Used 5+ times
FREE Resource
Enhance your content in a minute
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)
8.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
9. Create a Python program to iterate through a dictionary and print its key-value pairs.
print(my_dict.items())
for key, value in my_dict.items(): print(key, value)
for key, value in my_dict:
for key in my_dict:
9.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
10. How can you iterate through a dictionary in Python? Provide an example.
for key in my_dict:
for item in my_dict:
for value in my_dict.values():
for key, value in my_dict.items():
Similar Resources on Wayground
10 questions
Administrasi Sistem Jaringan
Quiz
•
12th Grade
10 questions
python-BTxâu
Quiz
•
9th - 12th Grade
11 questions
Python Library-1
Quiz
•
12th Grade
10 questions
SOAL EVALUASI MICROSOFT EXCEL
Quiz
•
12th Grade
10 questions
Topologies and Architecture
Quiz
•
9th - 12th Grade
10 questions
Word basics
Quiz
•
8th - 12th Grade
12 questions
Intro to Scratch 2
Quiz
•
KG - University
10 questions
KTTX-T4
Quiz
•
9th - 12th Grade
Popular Resources on Wayground
10 questions
Honoring the Significance of Veterans Day
Interactive video
•
6th - 10th Grade
9 questions
FOREST Community of Caring
Lesson
•
1st - 5th Grade
10 questions
Exploring Veterans Day: Facts and Celebrations for Kids
Interactive video
•
6th - 10th Grade
19 questions
Veterans Day
Quiz
•
5th Grade
14 questions
General Technology Use Quiz
Quiz
•
8th Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
15 questions
Circuits, Light Energy, and Forces
Quiz
•
5th Grade
19 questions
Thanksgiving Trivia
Quiz
•
6th Grade
