Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Week 3 - Python 2

Total questions: 30

Worksheet time: 17mins

Name
Class
Date
1.

A Python dictionary stores ...

a)

value - key pairs

b)

key - value pairs

2.
What data type is this?
quiz = {"Do you help out at home? ":"yes",        
"Do you beleive in Santa? ":"yes"
}
a)
list
b)
string
c)
dictionart
d)
dictionary
3.
Which symbol surrounds a dictionary?
a)
{
b)
(
c)
[
d)
:
4.

Items are accessed by their position in a dictionary

a)

True

b)

False

5.

________________method will returns number of key-value pairs in the given dictionary.

a)

len( )

b)

pop( )

c)

del( )

d)

keys( )

e)

values( )

6.

thisList = ["square", "circle", "triangle", "octagon"]

thisNumList = [1, 500, 21.7]

print(thisList)​

print(thisNumList)

a)

['square', 'circle', 'triangle', 'octagon']

[1, 500, 21.7]

b)

['square', 'circle', 'triangle', 'octagon']

c)

[1, 500, 21.7]

d)

['square', 'rectangle', 'triangle', 'octagon']

7.

thisList = ["square", "circle", "triangle", "octagon"]

print(thisList[3])

a)

octagon

b)

triangle

c)

circle

d)

square

8.

What does the code print?

a)

Coke

b)

Coke Coke_Zero Pepsi

c)

90 0 94

d)

Gobble

9.

Which statement adds 'Sprite':120 to the dictionary?

a)
b)
c)
d)
10.

True or False

For loop 1 produces the same result as for loop 2

a)

True

b)

False

11.

What are the missing statements to produce the output?

a)
b)
c)
d)
12.

How many times does the print(x, y) statement execute?

a)

0

b)

5

c)

16

d)

25

13.

What is the output?

a)

[[5, 10, 15], [2, 3, 16], [100], [30, 21, 100]]

b)

[30, 21, 100]

c)

[107]

d)

[[107], [13], [21]]

14.

What is the difference between return and print?

a)

Print will appear in the console, and return will give back the output where function is called.

b)

Return will appear in the console, and print will give back the output where function is called.

c)

For print, you need to save it in something. Return, you do not.

d)

For return, there is only one way to use it. With print, you can do a lot more.

15.

You can have empty {} when using f-strings.

a)

True

b)

False

16.

What is the difference between dictionaries and lists?

a)

Dictionaries and lists have different syntax, are not ordered, and have a key and a value opposed to one element

b)

There is nothing different. Just different way to create a list/dictionary.

c)

Dictionaries have elements when lists have a key and a value.

d)

Dictionaries and lists have different syntax, but otherwise are the same

17.

What would be the output?


a_dict = {'color': 'blue', 'fruit': 'apple', 'pet': 'dog'}


for key in a_dict:

print(key)

a)

'blue'

'apple'

'dog'

b)

color

fruit

pet

c)

blue

apple

dog

d)

'color'

'fruit'

'pet'

18.

Which statement is true?

a)

Parameters are global variables.

b)

Any variable created inside a function can be used outside.

c)

Any variable created inside a function cannot be used outside.

d)

Can only send primitives (boolean, String, int, float) as parameters

19.

class = "Python"

year = 2021


print(f'It is {2021} and I am in {class} class.')


What is the output?

a)

Error: Can only send variables as placeholders

b)

It is 2021 and I am in class class.

c)

It is year and I am in class class.

d)

It is 2021 and I am in Python class.

e)

It is 2021 and I am in "Python" class.

20.

What will be the value of last_jedi after the following code is run?

a)

["kylo", "rey", "finn", "luke"]

b)

["kylo", "rey", "finn"]

c)

3

d)

4

21.

What will be the value of authors after the following code is run?

a)

["Martin", "Rowling", "Tolkien"]

b)

["Martin"]

c)

["Rowling"]

d)

["Tolkien", "Rowling", "Martin"]

22.

What is the correct syntax to write a for loop to iterate through the list grades?

a)

for variable:

b)

for variable in grades

c)

variable in grades:

d)

for variable in grades:

23.

True or False

A Python Dictionary has two components, a key and a value.

a)

True

b)

False

24.

Each key/value pair in a dictionary is separated by this symbol:

a)

/

b)

,

c)

:

d)

;

25.

Using the [] operator, you can add or modify items in a:

a)

Stack

b)

Queue

c)

Dictionary

d)

Set

26.

Which data structure is immutable?

a)

Set

b)

Dictionary

c)

Tuple

27.

In Python, are dictionaries immutable?

a)

True

b)

False

28.

Which of the following is not a numeric datatype?

a)

Float

b)

Integer

c)

Complex Numbers

d)

Strings

29.

Which of the following datatype is denoted by the round brackets ()?

a)

List

b)

Boolean

c)

String

d)

Tuple

30.

Is the Grubhub guy ugly?

a)

Yes

b)

Yes

c)

Yes

d)

Yes