wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Week 11: Lists, Loops & "Failure"!

Total questions: 58

Worksheet time: 29mins

Name
Class
Date
1.
What output will this code produce?
a)
blue
b)
green
c)
red
d)
error
2.

Is this the correct code for a list?

register = {"Sam", "Pheobe", Georgia", Richard"}

a)

Yes

b)

No

3.

What is the index of “grape” in the list

[“apple”, “grape”, “orange”, “watermelon”]?

a)

0

b)

1

c)

2

d)

3

4.

What is the output of program below?


bicycles = ['trek', 'cannondale', 'redline', 'specialized']

print(bicycles[-1])

a)

trek

b)

cannondale

c)

redline

d)

specialized

5.
What letter will be printed on the screen after running this code:
a)
e
b)
x
c)
t
d)
Nothing prints
6.
What is the position of the name "Robert" in the following list:
a)
0
b)
1
c)
2
d)
3
7.
In the following code, "city" is an example of a what?
a)
List
b)
Loop
c)
Variable
d)
Array
8.
Each item in a list has an "address" or index. The first index in a Python list is what?
a)
0
b)
1
c)
a
d)
A
9.

In a list called "players" if you wanted to delete the item with an index of 3 which of the following examples of code would be correct?

a)

players.pop[2]

b)

players.delete(2)

c)

players.remove(2)

d)

players.pop(2)

10.

If you want to create an empty list called colors, which of the following pieces of code is correct?

a)

colors = [ ]

b)

colors = ( )

c)

colors = { }

d)

colours = [ ]

11.
What output will this code produce?
a)
Exeter
b)
4
c)
6
d)
city
12.
What output will this code produce?
a)
red
b)
['blue', 'green', 'red']
c)
['red', 'green', 'blue']
d)
error
13.
What output will this code produce?
a)
['blue', 'green', 'red', 'yellow']
b)
['blue', 'red', 'yellow']
c)
['yellow', 'red', 'green']
d)
['yellow', 'red', 'blue']
14.

What will line 3 OUTPUT?

a)

3

b)

2

c)

TRUE

d)

FALSE

15.

Which of these is the correct code for creating a list of names?

a)

nameList = John, Harry, Jesse, John, Harry, Harry

b)

nameList = ("John", "Harry", "Jesse", "John", "Harry", "Harry")

c)

nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]

d)

nameList = [John, Harry, Jesse, John, Harry, Harry]

16.

List items have an index number. In the following list, which item has the index number of 3?

["John", "Harry", "Jesse", "John", "Harry", "Harry"]

a)

"John"

b)

"Harry"

c)

"Jesse"

17.

Which of these pieces of code would return the name "Harry" from the following list?

nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]

a)

nameList()

b)

nameList[1]

c)

NameList(4)

d)

nameList["4"]

18.

The list needs one more name added to the end - "Felipe". Which piece of code below would do this?

nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]

a)

nameList.append(Felipe)

b)

append(nameList,"Felipe")

c)

nameList.append["Felipe",7]

d)

nameList.append("Felipe")

19.

Is this the correct code for a list?

register = {"Sam", "Pheobe", Georgia", Richard"}

a)

Yes

b)

No

20.

Consider this list, what will be the highest index the list can have:

li=[1,2,3,4,5]

a)

2

b)

3

c)

4

d)

5

21.

The count() method returns the number of times the specified element appears in the list.

What is the output of this code?

a)

3

b)

2

c)

1

d)

0

22.

Output of this code?

a)

[2,4,6,8,10]

b)

['2','4','6','8','10']

c)

[0,2,4,6,8]

d)

[10,8,6,4,2]

23.

What is the output of this code?

a)

X

b)

Y

c)

Error

24.

Which of the following functions is used to count the number of elements in a list ?

a)

count( )

b)

find( )

c)

len( )

d)

index( )

25.

What is the index of “grape” in the list

[“apple”, “grape”, “orange”, “watermelon”]?

a)

0

b)

1

c)

2

d)

3

26.

mylist = ["a","b"]

mylist[1] = "c"'

print(mylist)

a)

["a","c"]

b)

["a","b"]

c)

["a","b","c"]

d)

mylist

27.

What is a list in python?

a)

A collection of variables

b)

A collection of items assigned to a single variable

c)

A statement that cant be changed

d)

A Christmas list

28.

What is the index number for 'Spain'?

['England','Brazil','Spain','France']

a)

0

b)

1

c)

2

d)

3

29.

Which code would i use to add an item to a list?

a)

variable.add()

b)

variable.append()

c)

append.variable()

d)

add.variable()

30.

How do i remove something from a list?

a)

variable.append()

b)

variable.delete()

c)

variable.remove()

d)

variable=(new variable)

31.

What is used to separate elements in a list?

a)

Bracket

b)

Comma

c)

Full Stop

d)

Space

32.

What brackets are used to create a list?

a)

()

b)

[]

33.

A condition controlled loop is...

a)

A while loop

b)

A for loop

34.

Which of these operators means EQUAL TO?

a)

'='

b)

'=>'

c)

'<='

d)

'=='

35.

What will this code do?

a)

Print Numbers 1-11

b)

Print Numbers 1-10

c)

Print Numbers 2-10

d)

Print Error

36.

If we had a list "jointlist" that contained various integers, printing jointlist[0] would print:

a)

The first value

b)

The last value

c)

The average value in jointlist

d)

Nothing (null print)

37.

The keyword "break":

a)

Terminates a loop

b)

Pauses a loop briefly

c)

Sub-divides a memory space

d)

Shatters reality

38.

The built-in len() function returns:

a)

The number of elements in a collection

b)

The metric distance of a collection

c)

The L2 distance of a collection

d)

Measurements for a prismatic LENs

39.

In Python, ranges and slices stop one short of the specified value. This annoying condition is due to:

a)

Python being a zero-indexed language

b)

Inaccuracy in the binary-to-decimal conversion

c)

Perl hackers

d)

Lisp hackers

40.

If I wanted to reverse a string, I could slice it with:

a)

[::-1]

b)

[:::]

c)

[:backward]

d)

[.reverse()]

41.

We use list comprehensions instead of for loops to:

a)

Gain faster performance

b)

Write more compact code

c)

Flaunt our technical superiority

d)

Engender negative feelings in weaker programmers

42.

A while loop can be used in which of the following situations?

a)

Repeat a set of statements till a condition remains True.

b)

Repeat a set of statements a finite or an infinite number of times.

c)

Iterate through a string, list, and tuple.

d)

All of the above

43.

Which of these is the best description of a list in Python?

a)

A list is a collection of data that has an order and can be changed

b)

A list is a lot of variables

c)

A list is used for shopping

d)

A list is a collection of data that cannot hold duplicated data and cannot be changed

44.

In Python, the two types of loops are _____ and _______

a)

while

b)

for

c)

list

d)

if

45.

Loop that runs till the condition is true

a)

list

b)

while

c)

for

d)

if

46.

Kind of loop used when you know the number of times you want it to repeat

a)

list

b)

for

c)

while

d)

if

47.

Function range(3) is equivalent to "

a)

range(1,3)

b)

range(0,3)

c)

range(0,3,1)

d)

range(1,3,0)

48.

If you wished a loop to repeat 3 times what should you use?

a)

For counter in range(0,5):

b)

For counter in range(1,3):

c)

For counter in range(0,3):

49.

What does the '#' allow you to do?

a)

Repeat code

b)

Comment on code

c)

Print code

d)

End code

50.

Which of these will allow me to count from 0-20 in steps of 5?

a)

for x in range(0,20):

print(x)

b)

while x = (0,20,5):

print(x)

c)

for x in range(0,21,5):

print(x)

d)

for x in range(0,21,5):

print(y)

51.

If i want to continuously check for a correct answer, what loop would i use?

a)

for loop

b)

while loop

52.

What is the error in this code?

a)

incorrect variable name

b)

incorrect indentation

c)

incorrect speech marks

d)

incorrect loop

53.

The ............ operator is used to concatenate or join two or more strings.

a)

+

b)

*

c)

&

d)

None of the these

54.

To place the string "strawberries" in the first position of a list we use

a)

fruit.append("strawberries, 1")

b)

fruit.insert("strawberries",0)

c)

fruit.insert(1, "strawberries")

d)

fruit.insert(0, "strawberries")

55.

Which code would i use to add an item to a list?

a)

variable.add()

b)

variable.append()

c)

append.variable()

d)

add.variable()

56.

How do i remove something from a list?

a)

variable.append()

b)

variable.delete()

c)

variable.remove()

d)

variable=(new variable)

57.

What is the output of program below?


mariana_islands = ['Saipan', 'Tinian', 'Rota']

mariana_islands.remove('Tinian')

print(mariana_islands)

a)

['Saipan', 'Tinian', 'Rota']

b)

['Tinian', 'Rota']

c)

['Saipan', 'Tinian']

d)

['Saipan', 'Rota']

58.

What is the output of program below?


mariana_islands = ['Saipan', 'Tinian', 'Rota', 'Guam']

mariana_islands.sort()

print(mariana_islands)

a)

['Tinian', 'Saipan', 'Rota', 'Guam']

b)

['Guam', 'Tinian', 'Rota', 'Saipan']

c)

['Saipan', 'Rota', 'Guam', 'Tinian']

d)

['Guam', 'Rota', 'Saipan', 'Tinian']