wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

CONTROL STRUCTURES - LIST

Total questions: 25

Worksheet time: 15mins

Name
Class
Date
1.

In programming, what is iteration?

a)

The repetition of steps within a program

b)

The order in which instructions are carried out

c)

A decision point in a program

d)

Testing a program to make sure it works

2.
a)

5

4

3

2

1

b)

4

3

2

1

0

c)

5 4 3 2 1

d)

4 3 2 1 0

3.
a)

0 5 10

b)

5 10

c)

5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140......etc

d)

12 7 2

4.
a)

Welcome

b)

Try again!

c)

Error

d)

Enter your password

5.

In a Python program, what would be the iteration variable

(looping variable) in the FOR LOOP code?

a)

n

b)

num

c)

i

d)

value

6.

In a Python program, what would be the starting value in the FOR LOOP code?

a)

4

b)

25

c)

1

d)

0

7.

In a Python program, how many outputs will occur for the

snippet of code?

a)

15

b)

5

c)

6

d)

3

8.

Consider the loop control structure in programming. Which

term describes a loop that continues repeating without a

terminating (ending) condition?

a)

Conditional Loop

b)

Unlimited Loop

c)

Sequence Loop

d)

Infinite Loop

9.

What will print to the screen in this code?

a)

18

b)

-25

c)

-10

d)

-15

10.

What will be printed after running this FOR loop:

for number in range(6):

print(number)

a)

The number 6

b)

The number 5

c)

The numbers 0 - 5

d)

The numbers 1 - 6

11.
a)

1 2

b)

1 2 3

c)

error

d)

1 2 4 5 6 7 ..

12.

for x in range(7):

if (x == 3 or x==6):

continue

print(x)

a)

0

1

2

4

5

b)

0 1 2 4 5

c)

0

1

2

d)

1

2

4

5

13.

Which of the following commands will create a list?

a)

list1 = list()

b)

list1 = []

c)

list1 = list([1, 2, 3])

d)

all of the mentioned

14.

Suppose listExample is [‘h’,’e’,’l’,’l’,’o’], what is len(listExample)?

a)

5

b)

4

c)

None

d)

Error

15.

To shuffle the list(say list1) what function do we use?

a)

list1.shuffle()

b)

shuffle(list1)

c)

random.shuffle(list1)

d)

random.shuffleList(list1)

16.

Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?

a)

[2, 33, 222, 14]

b)

Error

c)

25

d)

[2, 33, 222, 14, 25]

17.

What will be the output of the following Python code?

>>>names = ['Amir', 'Bear', 'Charlton', 'Daman']

>>>print(names[-1][-1])

a)

A

b)

Daman

c)

n

d)

Error

18.

Suppose list1 = [0.5 * x for x in range(0, 4)], list1 is:

a)

[0, 1, 2, 3]

b)

[0, 1, 2, 3, 4]

c)

[0.0, 0.5, 1.0, 1.5]

d)

[0.0, 0.5, 1.0, 1.5, 2.0]

19.

To insert 5 to the third position in list1, we use which command?

a)

list1.insert(3, 5)

b)

list1.insert(2, 5)

c)

list1.add(3, 5)

d)

list1.append(3, 5)

20.

Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1.count(5)?

a)

0

b)

4

c)

1

d)

2

21.

How many elements are in m?

m = [[x, y] for x in range(0, 4) for y in range(0, 4)]

a)

8

b)

12

c)

16

d)

32

22.

What will be the output of the following Python code?


data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]


print(data[1][0][0])

a)

1

b)

2

c)

4

d)

5

23.

What will be the output of the following Python code?


a=[13,56,17]

a.append([87])

a.extend([45,67])

print(a)

a)

[13, 56, 17, [87], 45, 67]

b)

[13, 56, 17, 87, 45, 67]

c)

[13, 56, 17, 87,[ 45, 67]]

d)

[13, 56, 17, [87], [45, 67]]

24.

Write the list comprehension to pick out only negative integers from a given list ‘l’.

a)

[x<0 in l]

b)

[x for x<0 in l]

c)

[x in l for x<0]

d)

[x for x in l if x<0]

25.

Which of the following Python statements will result in the output: 6?


A = [[1, 2, 3],

[4, 5, 6],

[7, 8, 9]]

a)

A[2][3]

b)

A[2][1]

c)

A[1][2]

d)

A[3][2]