Worksheetskiểm tra 15 phút k8-for loop
Total questions: 23
Worksheet time: 14mins
What is the purpose of a for loop in Python?
To declare a variable
To execute a block of code multiple times\
To store multiple values in a single entity\
To perform a specific arithmetic operation
Which keyword is used to implement a for loop in Python?
loop
ilterate
for
for/loop
In a for loop, what does the range() function do?
It sets the upper limit of the loop
It creates a list of numbers
It specifies the increment value
It determines the number of iterations
How is the syntax for a for loop in Python structured?
for (initialization; condition; update)\
for {variable} in [sequence]:
for [sequence] in {variable}:
for {variable} in range():
What will the following code snippet output?
for i in range(3):
print(i)
0 1 2
1 2 3
3 3 3
0 1 2 3
What is the output of the following code?
for letter in "Python": print(letter)
P y t h o n
b. Python
['P', 'y', 't', 'h', 'o', 'n']
P h o n
How can you iterate through a list using a for loop in Python?
for i in list:
for i in list():
for i in range(list):
for i in len(list):
In a nested for loop, what does the outer loop control?
The inner loop
The number of iterations of the inner loop
The termination condition
The initialization step
In a nested for loop, what does the outer loop control?
The inner loop
The number of iterations of the inner loop
The termination condition
The initialization step
In a nested for loop, what does the outer loop control?
The inner loop
The number of iterations of the inner loop
The termination condition
The initialization step
In a nested for loop, what does the outer loop control?
The inner loop
The number of iterations of the inner loop
The termination condition
The initialization step
How can you create a decrementing for loop in Python?
for i in range(10, 0, -1):
for i in range(0, 10, -1):\
for i in range(10, -1, -1):\
for i in range(10, 0):
How can you create a decrementing for loop in Python?
for i in range(10, 0, -1):
for i in range(0, 10, -1):\
for i in range(10, -1, -1):\
for i in range(10, 0):
In Python, can a for loop be used with a string as the sequence?
no
yes
Maybe
only with a list
Which of the following will NOT cause an infinite loop in a for loop?
Forgetting to increment the loop variable
Incorrect termination condition
Using break statement
Incorrect range values
what does the outout of this statement:
range(1, 10, 3)
1, 10, 3
10, 10, 10
1, 1, 1
1, 4, 8
What is the output of this statemetn:
range(9)
1, 2, 3, 4, 5, 6, 7, 8
0 , 1, 2, 3, 4, 5, 6, 7, 8
0 , 1, 2, 3, 4, 5, 6, 7, 8, 9
1, 3, 5, 7, 9
What is output of this statement:
range(5, 0, -1)
4, 3, 2, 1, 0
4, 3, 2, 1
5, 4, 3, 2, 1, 0
5, 4, 3, 2, 1
what is the rule of range()
range(start, step)
range(start, stop, step)
range(start, stop, stock)
range(start, stop)
Which statement correctly demonstrates the use of nested for loops?
for i in range(3): for j in range(3):
for i in range(3) { for j in range(3): }
for i in range(3) and j in range(3):
for i in range(3); for j in range(3):
In a for loop, does the else block execute if the loop completes without encountering a break statement?
yes
no
it depends on the loop condition
Only if there is an increment statement
Viết chương trình in ra các số chia hết cho 5 từ 0 đến 100
rule of 3 variable in range(start, stop, step)
they are number
they are float
they are must be integer
they are float and integer
