wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Week 12 - Even More Lists

Total questions: 58

Worksheet time: 32mins

Name
Class
Date
1.

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

2.

When do you know when you come to the end of the loop?

a)

Its states End loop

b)

The command End is given

c)

The indentation stops

3.

What type of loop is used when you know how many times you want to repeat something?

a)

A WHILE Loop

b)

An IF function

c)

A FOR Loop

d)

A Variable

4.

Which type of loop iterates until instructed otherwise?

a)

FOR loop

b)

WHILE loop

5.

A condition is

a)

a statement that is either True or False

b)

a string

c)

an integer

d)

a list

6.

Which kind of loop would be used?


I need a guessing game program that will let me keep guessing until I get the right answer.

a)

FOR Loop

b)

WHILE Loop

7.

Which kind of loop would be used?


I need a program that will keep letting me add a monthly payment for 12 months.

a)

FOR Loop

b)

WHILE Loop

8.

numbers = [5, 14, 9, 17]

for number in numbers:

if number % 3 == 0:

print(number)


The output will be?

a)

17

b)

9

c)

14

9

17

d)

14

17

9.

Which two statements are used to implement iteration?

a)

IF and WHILE

b)

ELSE and WHILE

c)

FOR and WHILE

d)

IF and ELSE

10.

The condition for a while loop to continue could include which of the following?

a)

While something equals something

b)

While something is greater than something

c)

While something is True

d)

All of these

11.

Which of the following symbols is used in Python to mean "Equal to"?

a)

=

b)

!=

c)

==

d)

>=

12.

Which of the following symbols is used in Python to mean "Not equal to"?

a)

==

b)

!=

c)

<>

d)

><

13.

Which of the following symbols is used in Python to mean "Greater than or equal to"?

a)

<=

b)

>>

c)

>=

d)

=>

14.

What will be displayed on the screen when the following code is run?

esports = ["Donkey Kong", "Galaga", "Pac Man"]

print( esports[1] )

a)

Galaga

b)

Donkey Kong

c)

Pac Man

d)

Syntax error; you can't access individual list items this way

15.

Given a list with 3 items, what is the lowest and highest valid index number into that list?

a)

1 and 2

b)

0 and 2

c)

0 and 3

d)

3

16.

Given a list named "esports", which of the following statements will access only the first and second items in that list?

a)

esports(0:1)

b)

esports(0:3)

c)

esports[0:2]

d)

esports.range(0,2)

17.

What is displayed to the screen when the following code runs?

esports = ["Donkey Kong", "Galaga", "Pac Man"]

esports.insert(0,"Centipede")

print(esports)

a)

['Centipede', 'Centipede', 'Centipede']

b)

['Donkey Kong', 'Galaga', 'Pac Man', 'Centipede']

c)

['Centipede', 'Donkey Kong', 'Galaga', 'Pac Man']

d)

['Centipede', 'Galaga', 'Pac Man']

18.

What is displayed on the screen when the following code runs?

esports = ["Donkey Kong", "Galaga", "Pac Man"]

if ("Galaga" in esports):

print("Found it")

else:

print("Not here")

a)

Both "Found it" and "Not here"

b)

Not here

c)

Nothing - there is no output at all

d)

Found it

19.

What value is stored in the "total" variable after the following code runs?

total = 0

for i in range(1,4):

total = total + i

a)

0

b)

6

c)

7

d)

5

20.

Which of the following statements will cause a "while" loop to immediately exit without running any more statements in the body or checking the logical expression again?

a)

else

b)

break

c)

Continue

d)

Stop

21.

What is displayed to the screen when the following code runs?

esports = ["Donkey Kong", "Galaga", "Pac Man"]

esports.insert(2,"apple")

print(esports)

a)

["Donkey Kong", "Galaga", "Pac Man"]

b)

["Donkey Kong", "Galaga", "Pac Man", "apple"]

c)

[ "apple", "Donkey Kong", "Galaga", "Pac Man"]

d)

["Donkey Kong", "Galaga", "apple", "Pac Man"]

22.

Loops help us remove the redundancy of code when a task has to be repeated several times.

a)

True

b)

False

23.

With the break statement we can stop the loop even if the while condition is true

a)

break

b)

continue

24.

names = ["Mary", "Jane"]

What is the output of print(names[1])?

(a)  

25.

nums = [10, 9, 8]

nums[2] = 0

total = nums[0] + nums[1] + nums[2]

print(total)

(a)  

26.

x = [0,1,2]

x.append(3)

x.append(4)

print(len(x))

(a)  

27.

names = ["Mary", "Jane"]

names.remove("Mary")

names.append("Freya")

print(names[1])

(a)  

28.

nums = [4, 6, 8, 10, 12, 14]

nums.pop(4)

print(nums[0] + nums[1])

(a)  

29.

nums = [4, 6, 8, 10, 12, 14]

nums.pop(4)

What is the output of print(nums[4])?

(a)  

30.

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"

31.

word = "amazing"

For the given string, if we run word[2:5], what does it mean?

a)

It will extract alphabets from index 2 to index 4

b)

It will extract alphabets from index 2 to index 5

c)

It will extract alphabets from position 2 to position 4

d)

It will extract alphabets from position 2 to position 5

32.

word = "amazing"

For the given string if we run word[2:5:2] what does 2 mean in this function?

a)

It will pick only second alphabet

b)

It will pick only two alphabets

c)

It will pick every alternate alphabet

d)

It will pick first two alphabets

33.

Which brackets are used for Lists?

a)

( )

b)

[ ]

c)

{ }

d)

None of the above

34.

Which method is used to delete a value from the list and display it also?

a)

del()

b)

pop()

c)

popshow()

d)

remove()

35.

Which method is used to add a value at a specified position in the list?

a)

append

b)

extend

c)

insert

d)

pop

36.

Example of ... ?

a)

Indexing

b)

Appending

c)

Slicing

d)

Concatenation

37.

What is the output of the following list operation

aList = [10, 20, 30, 40, 50, 60, 70, 80]

print(aList[2:5])

print(aList[:4])

print(aList[3:])

a)

[20, 30, 40, 50]

[10, 20, 30, 40]

[30, 40, 50, 60, 70, 80]

b)

[30, 40, 50]

[10, 20, 30, 40]

[40, 50, 60, 70, 80]

c)

None of these

38.

What is the output of the following

aList = [5, 10, 15, 25]

print(aList[::-2])

a)

[15, 10, 5]

b)

[10, 5]

c)

[25, 10]

39.

What will be the output of the following Python code?

list1=[8,0,9,5]


print(list1[::-1])

a)

[5,9,0,8]

b)

[8,0,9]

c)

[8,0,9,5]

d)

[0,9,5]

40.

___________method adds a single item to the end of the list.

a)

extend( )

b)

append( )

c)

insert( )

41.

Is this the correct code for a list?

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

a)

Yes

b)

No

42.

What is the index of “grape” in the list?

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

a)

0

b)

1

c)

2

d)

3

43.

What is the output of the program below?


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

print(bicycles[-1])

a)

trek

b)

cannondale

c)

redline

d)

specialized

44.

List items are indexed, the first item has index [1], the second item has index [2], etc.

a)

True

b)

False

45.

List items can be of any data type:

a)

True

b)

False

46.

What is used to separate elements in a list?

a)

Bracket

b)

Comma

c)

Full Stop

d)

Space

47.

An empty list can be declared as

a)

fruitList = ""

b)

fruitList = ["empty"]

c)

fruitList == []

d)

fruitList = []

48.

Each item in a list has an "address" or index. The first index in a Python list is what?

a)

1

b)

0

c)

a

d)

A

49.

mylist = ["a","b"]

mylist[1] = "c"

print(mylist)

a)

["a","c"]

b)

["a","b"]

c)

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

d)

mylist

50.

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

51.

How do i remove something from a list?

a)

variable.append()

b)

variable.delete()

c)

variable.remove()

d)

variable=(new variable)

52.

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

a)

variable.add()

b)

variable.append()

c)

append.variable()

d)

add.variable()

53.

Which of the following keywords marks the begining of the function block?

a)

Func

b)

define

c)

def

d)

function

54.

what is a string?

a)

any numeric value

b)

any float value

c)

any character value

d)

any special symbol value

55.

Which answers below are correct for a string value in a variable?

a)

'string'

b)

"string"

c)

%string%

d)

#sring#

56.

fruit1="kiwi"

fruit2="strawberry"

print(len(fruit1))

print(len(fruit2))

a)

kiwi and strawberry

b)

4

10

c)

4 10

d)

410

57.

slicing string X="BOnVoyage"

print(X[0:5])

a)

BOnVoy

b)

BOnVo

c)

oyage

d)

bonvo

58.

Slicing string

x="BOnvoyage

print(x[4: ])

a)

BOnvo

b)

bonvo

c)

oyage

d)

VOYAGE