Loops Py Reading

Loops Py Reading

Assessment

Passage

Computers

9th - 10th Grade

Hard

Created by

Andrew Ward

FREE Resource

6 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the main purpose of loops in Python?

To repeat a block of code multiple times

To define functions

To handle exceptions

To create variables

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following is a type of loop in Python?

if loop

while loop

switch loop

case loop

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What will the following code output? count = 1 while count <= 5: print(count) count += 1

1 2 3 4 5

1 2 3 4 5 6

0 1 2 3 4

5 4 3 2 1

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

In a while loop, when does the loop stop executing?

When the condition becomes False

When the condition becomes True

After a fixed number of iterations

When an exception is raised

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What does the range() function do in a for loop?

Creates a sequence of numbers to loop over

Creates a list of strings

Creates a dictionary

Creates a set

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is a key difference between a while loop and a for loop?

while loop continues as long as a condition is True, for loop iterates over a sequence

while loop iterates over a sequence, for loop continues as long as a condition is True

while loop is used for strings, for loop is used for numbers

while loop is faster than for loop