Iteration in Python Quiz

Iteration in Python Quiz

12th Grade

9 Qs

quiz-placeholder

Similar activities

python 3

python 3

11th - 12th Grade

10 Qs

Python Nested Loops Quiz

Python Nested Loops Quiz

9th - 12th Grade

10 Qs

python

python

9th - 12th Grade

10 Qs

Python Boolean

Python Boolean

11th - 12th Grade

11 Qs

H -Subprograms

H -Subprograms

12th Grade - University

12 Qs

Python Quiz 1

Python Quiz 1

6th Grade - University

12 Qs

Quiz sobre Funções em Python

Quiz sobre Funções em Python

12th Grade

9 Qs

Python Basics

Python Basics

6th - 12th Grade

9 Qs

Iteration in Python Quiz

Iteration in Python Quiz

Assessment

Quiz

Computers

12th Grade

Hard

Created by

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():