Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

kiểm tra 15 phút k8-for loop

Total questions: 23

Worksheet time: 14mins

Name
Class
Date
1.

What is the purpose of a for loop in Python?

a)

To declare a variable

b)

To execute a block of code multiple times\

c)

To store multiple values in a single entity\

d)

To perform a specific arithmetic operation

2.

Which keyword is used to implement a for loop in Python?

a)

loop

b)

ilterate

c)

for

d)

for/loop

3.

In a for loop, what does the range() function do?

a)

It sets the upper limit of the loop

b)

It creates a list of numbers

c)

It specifies the increment value

d)

It determines the number of iterations

4.

How is the syntax for a for loop in Python structured?

a)

for (initialization; condition; update)\

b)

for {variable} in [sequence]:

c)

for [sequence] in {variable}:

d)

for {variable} in range():

5.

What will the following code snippet output?

for i in range(3):

print(i)

a)

0 1 2

b)

1 2 3

c)


3 3 3

d)

0 1 2 3

6.

What is the output of the following code?

for letter in "Python": print(letter)

a)

P y t h o n

b)

b. Python

c)

['P', 'y', 't', 'h', 'o', 'n']

d)

P h o n

7.

How can you iterate through a list using a for loop in Python?

a)

for i in list:

b)

for i in list():

c)

for i in range(list):

d)

for i in len(list):

8.

In a nested for loop, what does the outer loop control?

a)

The inner loop

b)

The number of iterations of the inner loop

c)

The termination condition

d)

The initialization step

9.

In a nested for loop, what does the outer loop control?

a)

The inner loop

b)

The number of iterations of the inner loop

c)

The termination condition

d)

The initialization step

10.

In a nested for loop, what does the outer loop control?

a)

The inner loop

b)

The number of iterations of the inner loop

c)

The termination condition

d)

The initialization step

11.

In a nested for loop, what does the outer loop control?

a)

The inner loop

b)

The number of iterations of the inner loop

c)

The termination condition

d)

The initialization step

12.

How can you create a decrementing for loop in Python?

a)

for i in range(10, 0, -1):

b)

for i in range(0, 10, -1):\

c)

for i in range(10, -1, -1):\

d)

for i in range(10, 0):

13.

How can you create a decrementing for loop in Python?

a)

for i in range(10, 0, -1):

b)

for i in range(0, 10, -1):\

c)

for i in range(10, -1, -1):\

d)

for i in range(10, 0):

14.

In Python, can a for loop be used with a string as the sequence?

a)

no

b)

yes

c)

Maybe

d)

only with a list

15.

Which of the following will NOT cause an infinite loop in a for loop?

a)

Forgetting to increment the loop variable

b)

Incorrect termination condition

c)

Using break statement

d)

Incorrect range values

16.

what does the outout of this statement:

range(1, 10, 3)

a)

1, 10, 3

b)

10, 10, 10

c)

1, 1, 1

d)

1, 4, 8

17.

What is the output of this statemetn:

range(9)

a)

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

b)

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

c)

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

d)

1, 3, 5, 7, 9

18.

What is output of this statement:

range(5, 0, -1)

a)

4, 3, 2, 1, 0

b)

4, 3, 2, 1

c)

5, 4, 3, 2, 1, 0

d)

5, 4, 3, 2, 1

19.

what is the rule of range()

a)

range(start, step)

b)

range(start, stop, step)

c)

range(start, stop, stock)

d)

range(start, stop)

20.

Which statement correctly demonstrates the use of nested for loops?

a)

for i in range(3): for j in range(3):

b)

for i in range(3) { for j in range(3): }

c)


for i in range(3) and j in range(3):

d)

for i in range(3); for j in range(3):

21.

In a for loop, does the else block execute if the loop completes without encountering a break statement?

a)

yes

b)

no

c)

it depends on the loop condition

d)

Only if there is an increment statement

22.

Viết chương trình in ra các số chia hết cho 5 từ 0 đến 100

4 lines
23.

rule of 3 variable in range(start, stop, step)

a)

they are number

b)

they are float

c)

they are must be integer

d)

they are float and integer