wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Unit 8 Quiz

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

Which of the following data structures is immutable?

a)

Tuple

b)

List

c)

Dictionary

d)

2D List

2.

What does this program print?

heights = [65, 56, 67, 48, 64]

heights.sort()

heights.extend([60, 61, 62])

heights.remove(67)

print(heights)

a)

[48, 56, 64, 65, [60, 61, 62]]

b)

[48, 56, 60, 61, 62, 64, 65]

c)

[48, 56, 64, 65, 60, 61, 62]

d)

error loop

3.

How many times does this program print That's a large class!?

num_students = [23, 21, 33, 35, 24, 35]

for num in num_students: if num > 23:

print("That's a large class!")

a)

0

b)

1

c)

4

d)

6

4.

What would the following program print to the screen when run?

my_list = [7, 0, 0, "d", "n", "o", "B"]

my_list.reverse()

for thing in my_list: print(thing)

a)

7 0 0 d n o B

b)

0 0 7 B o n d

c)

B o n d 0 0 7

d)

700donB

5.

Given the following list: my_list = ["s", "Z", "e", "c", "c", "e", "r", "h", "e", "p", "t"] which program below would give the following output:

s e c r e t

a)

for index in my_list: if index % 2 == 0: print(my_list[index])

b)

for index in range(my_list): if index % 2 == 0: print(my_list[index])

c)

for index in len(my_list): if index % 2 == 0: print(my_list[index])

d)

for index in range(len(my_list)): if index % 2 == 0: print(my_list[index])

6.

Which values entered into ‘my_list’ would print a value of ‘-1’ after the program has run?

my_list = [...] num = 0

for thing in my_list:

num = num - thing

print(num)

a)

5, -10, 6

b)

-10, -5, 6

c)

-5, 10, 6

d)

-5, 0, 10, 6

7.

Which of the following programs would produce the following output:

1. honey 2. bread 3. jelly 4. plates

a)

my_list = ["honey", "bread", "jelly", "plates"] for index in range(len(my_list)): print(str(index) + ". " + my_list)

b)

my_list = ["honey", "bread", "jelly", "plates"] for index in range(len(my_list)): print(str(index+1) + ". " + my_list[index])

c)

my_list = ["honey", "bread", "jelly", "plates"] for index in my_list: print(str(index+1) + ". " + my_list[index])

d)

my_list = ["honey", "bread", "jelly", "plates"] for index in len(my_list): print(str(index) + ". " + my_list[index])

8.

Which of the following programs would alter my_list to consist of the following:

[‘red’, ‘green’, ‘blue’, ‘orange’, ‘yellow’]

a)

my_list = ['red', 'green', 'blue', 'orange'] my_list.append('yellow')

b)

my_list = ['red', 'green', 'blue', 'orange'] my_list.extend('yellow')

c)

my_list = ['red', 'green', 'blue', 'orange'] my_list.replace('yellow')

d)

my_list = ['red', 'green', 'blue', 'orange'] my_list.add('yellow')

9.

What will be the output of the following program?

my_list = [1, 2, 3, 4]

num = 5

for index in range(len(my_list)):

my_list.append(num + index)

print(my_list)

a)

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

b)

[1, 2, 3, 4, 5]

c)

[1, 2, 3, 4, 6, 7, 8, 9]

d)

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

10.

What kind of data structure is user_data in the following declaration?

user_data = ("TJ", 24, "artLover123")

a)

Tuple

b)

List

c)

String

d)

2d List

11.

What kind of data structure is user_data in the following declaration?

user_data = ["TJ", 24, "artLover123"]

a)

Tuple

b)

List

c)

String

d)

2d List

12.

Which of the following lines of code will cause an error? Use the following definition of ages:

ages = (12, 5, 8)

a)

ages = ages + (1, 3, 5)

b)

print(ages[2])

c)

ages = ages[2:]

d)

ages[0] = 3

13.

What does this code snippet print?

fruit = ["b", "n", "n"]

print("a".join(fruit))

a)

bnn

b)

ba na na

c)

banan

d)

banana

14.

What is the value of num after this code runs?

shapes = ["triangle", "square", "hexagon", "circle", "pentagon"]

num = len(shapes)

a)

0

b)

4

c)

5

d)

35

15.

What does this program print?

sentence = "My favorite animal is a dog or chipmunk"

sentence_list = sentence.split()

sentence_list[-3] = "penguin"

sentence = " ".join(sentence_list)

print(sentence)

a)

My favorite animal is a dog or penguin

b)

My favorite animal is a penguin or chipmunk

c)

My favorite animal is a dog penguin chipmunk

d)

My favorite animal is a dog or chipmunk