wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Chapter 10 Review

Total questions: 25

Worksheet time: 13mins

Name
Class
Date
1.

What will run when the following code is executed?


my_dict = {

'name': 'Nick',

'age': 31,

'occupation': 'Dentist',

}


for key in my_dict:

print key, my_dict[key]

a)

"age 31"

"name Nick"

"occupation Dentist"

b)

{age 31}

{name Nick}

{occupation Dentist}

c)

age 31

name Nick

occupation Dentist

d)

(age 31)

(name Nick)

(occupation Dentist)

2.

What will run when the following code is executed?


my_dict = {

'name': 'Nick',

'age': 31,

'occupation': 'Dentist',

}


print my_dict.values()

a)

[31, 'Nick', 'Dentist']

b)

"31, 'Nick', 'Dentist'

c)

{31, 'Nick', 'Dentist'}

d)

31, Nick, Dentist

3.

What will run when the following code is executed?


my_dict = {

'name': 'Nick',

'age': 31,

'occupation': 'Dentist',

}


print my_dict.keys()

a)

age, name, occupation

b)

['age', 'name', 'occupation']

c)

{age, name, occupation}

d)

*age, name, occupation*

4.

What will run when the following code is executed?


evens_to_18 = [i for i in range(19) if i % 2 == 0]


print evens_to_18

a)

0,2,4,6,8,10,12,14,16,18

b)

{0,2,4,6,8,10,12,14,16,18}

c)

[0,2,4,6,8,10,12,14,16,18]

d)

"0,2,4,6,8,10,12,14,16,18"

5.

What will run when the following code is executed?


evens_to_18 = [i for i in range(19) if i % 4 == 0]


print evens_to_18

a)

0,4,8,12,16

b)

*0,4,8,12,16*

c)

{0,4,8,12,16}

d)

[0,4,8,12,16]

6.

What will run when the following code is executed?


even_squares = [x ** 2 for x in range(1, 8) if x % 2 == 0]


print even_squares

a)

4,16,36

b)

{4,16,36}

c)

[4,16,36]

d)

*4,16,36*

7.

What will run when the following code is executed?


doubles_by_3 = [x * 2 for x in range(1, 12) if (x * 2) % 3 == 0]


print doubles_by_3

a)

[6,12,18]

b)

6,12,18

c)

{6,12,18}

d)

*6,12,18*

8.

What will run when the following code is executed?


l = [i ** 2 for i in range(1, 11)]


print l [2:9:2]

a)

{9,25,49,81}

b)

[9,25,49,81]

c)

9,25,49,81

d)

*9,25,49,81*

9.

List slicing includes the following:

a)

[start:end:stride]

b)

{start:end:stride}

c)

start:end:stride

d)

"start": "end": "stride"

10.

When list slicing:


start is "inclusive"

a)

True

b)

False

11.

When list slicing:


end is "exclusive"

a)

True

b)

False

12.

When list slicing:


stride describes the syntax of the function

a)

True

b)

False

13.

What will run when the following code is executed?


my_list = range(1, 11)


print my_list[::2]

a)

1, 3, 5, 7, 9

b)

[1, 3, 5, 7, 9]

c)

{1, 3, 5, 7, 9}

d)

*1, 3, 5, 7, 9*

14.

What will run when the following code is executed?


my_list = range(1, 16)


print my_list[::2]

a)

{1, 3, 5, 7, 9, 11, 13, 15}

b)

(1, 3, 5, 7, 9, 11, 13, 15)

c)

[1, 3, 5, 7, 9, 11, 13, 15]

d)

"1, 3, 5, 7, 9, 11, 13, 15"

15.

What will run when the following code is executed?


my_list = range(1, 11)


backwards = my_list[::-1]


print backwards

a)

10, 9, 8, 7, 6, 5, 4, 3, 2, 1

b)

(10, 9, 8, 7, 6, 5, 4, 3, 2, 1)

c)

*10, 9, 8, 7, 6, 5, 4, 3, 2, 1*

d)

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

16.

What will run when the following code is executed?


to_one_hundred = range(101)


backwards_by_tens = to_one_hundred[::-10]


print backwards_by_tens

a)

[0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]

b)

[100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0]

c)

100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0

d)

0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100

17.

What will run when the following code is executed?


to_one_hundred = range(101)


backwards_by_twenty = to_one_hundred[::-20]


print backwards_by_twenty

a)

100, 80, 60, 40, 20, 0

b)

[0, 20, 40, 60, 80, 100]

c)

[100, 80, 60, 40, 20, 0]

d)

0, 20, 40, 60, 80, 100

18.

What will run when the following code is executed?


odds = to_21 [::2]


print odds

a)

[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21]

b)

1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21

c)

[21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]

d)

21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1

19.

What will run when the following code is executed?


my_list = range(16)


print filter(lambda x: x % 3 == 0, my_list)

a)

[0, 3, 6, 9, 12, 15]

b)

0, 3, 6, 9, 12, 15

c)

{0, 3, 6, 9, 12, 15}

d)

"0, 3, 6, 9, 12, 15"

20.

What will run when the following code is executed?


my_list = range(16)


print filter(lambda x: x % 5 == 0, my_list)

a)

{0,5,10,15}

b)

0,5,10,15

c)

(0,5,10,15)

d)

[0,5,10,15]

21.

What will run when the following code is executed?


fives = [x for x in range(1, 16) if x % 3 == 0 or x % 5 == 0]


print fives

a)

[0,5,10,15]

b)

{5,10,15}

c)

*3, 5, 6, 9, 10, 12, 15*

d)

[5,10,15]

22.

Which method returns the a list of the dictionary's keys?

a)

.keys[ ]

b)

.keys( )

c)

.keys { }

d)

None of these options

23.

Which of the following methods returns a list of the dictionary's values?

a)

.values( )

b)

.values[ ]

c)

.values" "

d)

None of these options

24.

Which method returns an array of tuples?

a)

.items[ ]

b)

.items( )

c)

.items{ }

d)

None of these options

25.

List slicing does not allow the user to access elements of a list in a specific manner.

a)

True

b)

False