
Iteration in Python Quiz

Quiz
•
Computers
•
12th Grade
•
Hard
Andrew Asante
Used 5+ times
FREE Resource
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
12 questions
Основи Python

Quiz
•
7th - 12th Grade
10 questions
python quiz

Quiz
•
6th Grade - Professio...
14 questions
Christmas Programming Quiz

Quiz
•
12th Grade
10 questions
PCEP Section 1E: Perform Input/Output console operations

Quiz
•
12th Grade
12 questions
Python Εισαγωγή

Quiz
•
12th Grade
10 questions
Общие сведения о языке программирования Python

Quiz
•
9th - 12th Grade
12 questions
Project-Stem Unit 1 python coding

Quiz
•
9th - 12th Grade
10 questions
Python Math

Quiz
•
1st - 12th Grade
Popular Resources on Wayground
10 questions
Video Games

Quiz
•
6th - 12th Grade
20 questions
Brand Labels

Quiz
•
5th - 12th Grade
15 questions
Core 4 of Customer Service - Student Edition

Quiz
•
6th - 8th Grade
15 questions
What is Bullying?- Bullying Lesson Series 6-12

Lesson
•
11th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
22 questions
Adding Integers

Quiz
•
6th Grade
10 questions
Exploring Digital Citizenship Essentials

Interactive video
•
6th - 10th Grade