wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Long Test Part 2 - Loop Structures in Python_IT1107

Total questions: 26

Worksheet time: 13mins

Name
Class
Date
1.

Which statement best describes a while loop?

a)

It runs a block of code exactly once.

b)

It runs a fixed number of times determined at the start.

c)

It always executes at least one time.

d)

It runs as long as its condition remains true.

2.

What is a common cause of an infinite loop in a while loop?

a)

Using a counter inside the loop

b)

A condition that eventually becomes false

c)

A variable in the condition that never changes

d)

Using the range() function

3.

How many times is a while loop guaranteed to run?

a)

At least once

b)

At least twice

c)

Possibly zero times

d)

Exactly the same number of times as a for loop

4.

What is an advantage of a for loop over a while loop?

a)

It can loop infinitely if needed

b)

It is less likely to loop forever

c)

It allows more complex conditions

d)

It must use a numeric counter

5.

Which initial value would cause the following loop to run forever?

a)

0

b)

5

c)

-1

d)

10

6.

What is the purpose of a User Input Loop pattern?

a)

To count down values in a list

b)

To ensure the user enters correct data

c)

To loop the program infinitely

d)

To avoid using if statements

7.

Which statement is true about Do-Until loop patterns in Python?

a)

They always execute zero times

b)

They require a built-in do keyword

c)

They restructure logic so the loop runs at least once

d)

They are identical to for loops

8.

What does the REPL (Read-Evaluate-Print Loop) pattern do?

a)

Repeatedly asks for input and processes it

b)

Prints values from a list until it finds -1

c)

Only reads user input but never evaluates

d)

Only evaluates expressions without printing

9.

In a List-While pattern, which error commonly occurs if one is not careful in using it?

a)

String formatting error

b)

Using incorrect indentation

c)

Accessing an index out of bounds

d)

Invalid variable naming

10.

What is the main difference between for and while loops?

a)

for loops are safer but less flexible

b)

They behave identically in all situations

c)

while loops are safer than for loops

d)

for loops can run infinitely

11.

How many times will a for loop iterate when given an empty list?

a)

One time

b)

There’s no way to know

c)

Until stopped manually

d)

Zero times

12.

What is the iteration variable in a for loop?

a)

The list being iterated through

b)

The index number of the current iteration

c)

A new variable that stores each element of the list one at a time

d)

The total number of items in the list

13.

What is the type of the iteration variable in the code below?

a)

int

b)

str

c)

list[str]

d)

float

14.

What is the main purpose of the header in a for loop?

a)

To define the number of iterations

b)

To declare the variable types

c)

To specify the iteration variable and the iteration list

d)

To store the output of the loop

15.

In a for loop, how many statements inside the loop body are executed per list element?

a)

Only one

b)

Only the last statement

c)

Only the first statement

d)

All statements inside the indented block

16.

After the third iteration of the Count Pattern (count = count + 1), the value of count is:

a)

0

b)

6

c)

3

d)

Depends on list length

17.

After the first iteration of the loop, what is the value of sum?

a)

4

b)

0

c)

2

d)

6

18.

What is the purpose of the Map Pattern?

a)

To count items in a list

b)

To transform each element into a new list

c)

To detect infinite loops

d)

To find the maximum value in a list

19.

What does the following code print?

a)

6

b)

12

c)

24

d)

2, 4, 6

20.

When appending to a list you are currently iterating over, why does it cause an infinite loop?

a)

The loop ignores the new items

b)

The list becomes too short

c)

Python does not allow list modification

d)

The loop keeps discovering newly added items and never finishes

21.

What is the final value of count?

a)

0

b)

1

c)

3

d)

4

22.

What does this code print?

a)

_hi_there

b)

hithere

c)

hi_there_

d)

hi, there,_

23.

What is the output of the following map-pattern code?

a)

[1, 2, 3]

b)

[2, 4, 6]

c)

[1, 4, 9]

d)

[2, 3, 4]

24.

What happens when this code is executed?

a)

It prints:

["apple", "mango"]

b)

It prints:

["apple", "mango", "apples", "mangos"]

c)

Infinite loop or very long list

d)

Error: cannot modify a list during iteration

25.

What does this code print?

a)

20 30

b)

30 60

c)

40 90

d)

Error: grade is not accessible outside the loop

26.

What does the following code output?

a)

5

b)

3

c)

2

d)

8