NEW
Font size
WorksheetsLong Test Part 2 - Loop Structures in Python_IT1107
Total questions: 26
Worksheet time: 13mins
Which statement best describes a while loop?
It runs a block of code exactly once.
It runs a fixed number of times determined at the start.
It always executes at least one time.
It runs as long as its condition remains true.
What is a common cause of an infinite loop in a while loop?
Using a counter inside the loop
A condition that eventually becomes false
A variable in the condition that never changes
Using the range() function
How many times is a while loop guaranteed to run?
At least once
At least twice
Possibly zero times
Exactly the same number of times as a for loop
What is an advantage of a for loop over a while loop?
It can loop infinitely if needed
It is less likely to loop forever
It allows more complex conditions
It must use a numeric counter
Which initial value would cause the following loop to run forever?
0
5
-1
10
What is the purpose of a User Input Loop pattern?
To count down values in a list
To ensure the user enters correct data
To loop the program infinitely
To avoid using if statements
Which statement is true about Do-Until loop patterns in Python?
They always execute zero times
They require a built-in do keyword
They restructure logic so the loop runs at least once
They are identical to for loops
What does the REPL (Read-Evaluate-Print Loop) pattern do?
Repeatedly asks for input and processes it
Prints values from a list until it finds -1
Only reads user input but never evaluates
Only evaluates expressions without printing
In a List-While pattern, which error commonly occurs if one is not careful in using it?
String formatting error
Using incorrect indentation
Accessing an index out of bounds
Invalid variable naming
What is the main difference between for and while loops?
for loops are safer but less flexible
They behave identically in all situations
while loops are safer than for loops
for loops can run infinitely
How many times will a for loop iterate when given an empty list?
One time
There’s no way to know
Until stopped manually
Zero times
What is the iteration variable in a for loop?
The list being iterated through
The index number of the current iteration
A new variable that stores each element of the list one at a time
The total number of items in the list
What is the type of the iteration variable in the code below?
int
str
list[str]
float
What is the main purpose of the header in a for loop?
To define the number of iterations
To declare the variable types
To specify the iteration variable and the iteration list
To store the output of the loop
In a for loop, how many statements inside the loop body are executed per list element?
Only one
Only the last statement
Only the first statement
All statements inside the indented block
After the third iteration of the Count Pattern (count = count + 1), the value of count is:
0
6
3
Depends on list length
After the first iteration of the loop, what is the value of sum?
4
0
2
6
What is the purpose of the Map Pattern?
To count items in a list
To transform each element into a new list
To detect infinite loops
To find the maximum value in a list
What does the following code print?
6
12
24
2, 4, 6
When appending to a list you are currently iterating over, why does it cause an infinite loop?
The loop ignores the new items
The list becomes too short
Python does not allow list modification
The loop keeps discovering newly added items and never finishes
What is the final value of count?
0
1
3
4
What does this code print?
_hi_there
hithere
hi_there_
hi, there,_
What is the output of the following map-pattern code?
[1, 2, 3]
[2, 4, 6]
[1, 4, 9]
[2, 3, 4]
What happens when this code is executed?
It prints:
["apple", "mango"]
It prints:
["apple", "mango", "apples", "mangos"]
Infinite loop or very long list
Error: cannot modify a list during iteration
What does this code print?
20 30
30 60
40 90
Error: grade is not accessible outside the loop
What does the following code output?
5
3
2
8
