NEW
Font size
WorksheetsCONTROL STRUCTURES - LIST
Total questions: 25
Worksheet time: 15mins
In programming, what is iteration?
The repetition of steps within a program
The order in which instructions are carried out
A decision point in a program
Testing a program to make sure it works
5
4
3
2
1
4
3
2
1
0
5 4 3 2 1
4 3 2 1 0
0 5 10
5 10
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
12 7 2
Welcome
Try again!
Error
Enter your password
In a Python program, what would be the iteration variable
(looping variable) in the FOR LOOP code?
n
num
i
value
In a Python program, what would be the starting value in the FOR LOOP code?
4
25
1
0
In a Python program, how many outputs will occur for the
snippet of code?
15
5
6
3
Consider the loop control structure in programming. Which
term describes a loop that continues repeating without a
terminating (ending) condition?
Conditional Loop
Unlimited Loop
Sequence Loop
Infinite Loop
What will print to the screen in this code?
18
-25
-10
-15
What will be printed after running this FOR loop:
for number in range(6):
print(number)
The number 6
The number 5
The numbers 0 - 5
The numbers 1 - 6
1 2
1 2 3
error
1 2 4 5 6 7 ..
for x in range(7):
if (x == 3 or x==6):
continue
print(x)
0
1
2
4
5
0 1 2 4 5
0
1
2
1
2
4
5
Which of the following commands will create a list?
list1 = list()
list1 = []
list1 = list([1, 2, 3])
all of the mentioned
Suppose listExample is [‘h’,’e’,’l’,’l’,’o’], what is len(listExample)?
5
4
None
Error
To shuffle the list(say list1) what function do we use?
list1.shuffle()
shuffle(list1)
random.shuffle(list1)
random.shuffleList(list1)
Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?
[2, 33, 222, 14]
Error
25
[2, 33, 222, 14, 25]
What will be the output of the following Python code?
>>>names = ['Amir', 'Bear', 'Charlton', 'Daman']
>>>print(names[-1][-1])
A
Daman
n
Error
Suppose list1 = [0.5 * x for x in range(0, 4)], list1 is:
[0, 1, 2, 3]
[0, 1, 2, 3, 4]
[0.0, 0.5, 1.0, 1.5]
[0.0, 0.5, 1.0, 1.5, 2.0]
To insert 5 to the third position in list1, we use which command?
list1.insert(3, 5)
list1.insert(2, 5)
list1.add(3, 5)
list1.append(3, 5)
Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1.count(5)?
0
4
1
2
How many elements are in m?
m = [[x, y] for x in range(0, 4) for y in range(0, 4)]
8
12
16
32
What will be the output of the following Python code?
data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
print(data[1][0][0])
1
2
4
5
What will be the output of the following Python code?
a=[13,56,17]
a.append([87])
a.extend([45,67])
print(a)
[13, 56, 17, [87], 45, 67]
[13, 56, 17, 87, 45, 67]
[13, 56, 17, 87,[ 45, 67]]
[13, 56, 17, [87], [45, 67]]
Write the list comprehension to pick out only negative integers from a given list ‘l’.
[x<0 in l]
[x for x<0 in l]
[x in l for x<0]
[x for x in l if x<0]
Which of the following Python statements will result in the output: 6?
A = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
A[2][3]
A[2][1]
A[1][2]
A[3][2]
