PF Python Loops

PF Python Loops

Assessment

Interactive Video

Information Technology (IT)

9th - 12th Grade

Hard

Created by

Amy Austin

FREE Resource

12 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

A Python `while` loop is initialized with `value = 1` and the condition `while value < 10:`. Inside the loop, `value` is printed, and then incremented by 1. What numbers will be printed?

1, 2, 3, 4, 5, 6, 7, 8, 9

1, 2, 3, 4, 5, 6, 7, 8, 9, 10

0, 1, 2, 3, 4, 5, 6, 7, 8, 9

0, 1, 2, 3, 4, 5, 6, 7, 8

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

A `while` loop is set up to print numbers starting from 1, incrementing by 1, as long as the value is less than or equal to 10. If a `break` statement is added inside the loop, triggered when the value equals 5, what will be the final output?

1, 2, 3, 4

1, 2, 3, 4, 5

1, 2, 3, 4, 5, 6, 7, 8, 9, 10

An infinite loop

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

In a `while` loop, if a `continue` statement is encountered when a specific condition is met, what is the immediate effect on the loop's execution?

The loop terminates completely.

The program exits.

The current iteration is skipped, and the loop proceeds to the next iteration.

The loop restarts from the beginning with the initial condition.

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Consider a Python list `names = ["Dave", "Sara", "John"]`. If a `for` loop iterates through this list using `for x in names: print(x)`, what will be the output?

"Dave", "Sara", "John" printed on a single line.

"Dave", "Sara", "John" each printed on a new line.

Only "Dave" will be printed.

An error will occur because `x` is not defined.

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Consider a Python for loop iterating through names = ["Dave", "Sara", "John"]. If the current name is "Sara", the loop executes a break statement. A print(x) statement is placed after the if condition. What will be the output?

Dave

Dave, Sara

Dave, Sara, John

Dave, John

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Consider a Python for loop iterating through names = ["Dave", "Sara", "John"]. If the current name is "Sara", the loop executes a continue statement. A print(x) statement is placed after the if condition. What will be the output?

Dave

Dave, Sara

Dave, Sara, John

Dave, John

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What numbers will be printed by the Python code for x in range(2, 5): print(x)?

0, 1, 2, 3, 4

2, 3, 4

2, 3, 4, 5

0, 1, 2, 3

Create a free account and access millions of resources

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

By signing up, you agree to our Terms of Service & Privacy Policy

Already have an account?