WorksheetsWeek 3 - Python 2
Total questions: 30
Worksheet time: 17mins
A Python dictionary stores ...
value - key pairs
key - value pairs
quiz = {"Do you help out at home? ":"yes",
"Do you beleive in Santa? ":"yes"}
Items are accessed by their position in a dictionary
True
False
________________method will returns number of key-value pairs in the given dictionary.
len( )
pop( )
del( )
keys( )
values( )
thisList = ["square", "circle", "triangle", "octagon"]
thisNumList = [1, 500, 21.7]
print(thisList)
print(thisNumList)
['square', 'circle', 'triangle', 'octagon']
[1, 500, 21.7]
['square', 'circle', 'triangle', 'octagon']
[1, 500, 21.7]
['square', 'rectangle', 'triangle', 'octagon']
thisList = ["square", "circle", "triangle", "octagon"]
print(thisList[3])
octagon
triangle
circle
square
What does the code print?
Coke
Coke Coke_Zero Pepsi
90 0 94
Gobble
Which statement adds 'Sprite':120 to the dictionary?
True or False
For loop 1 produces the same result as for loop 2
True
False
What are the missing statements to produce the output?
How many times does the print(x, y) statement execute?
0
5
16
25
What is the output?
[[5, 10, 15], [2, 3, 16], [100], [30, 21, 100]]
[30, 21, 100]
[107]
[[107], [13], [21]]
What is the difference between return and print?
Print will appear in the console, and return will give back the output where function is called.
Return will appear in the console, and print will give back the output where function is called.
For print, you need to save it in something. Return, you do not.
For return, there is only one way to use it. With print, you can do a lot more.
You can have empty {} when using f-strings.
True
False
What is the difference between dictionaries and lists?
Dictionaries and lists have different syntax, are not ordered, and have a key and a value opposed to one element
There is nothing different. Just different way to create a list/dictionary.
Dictionaries have elements when lists have a key and a value.
Dictionaries and lists have different syntax, but otherwise are the same
What would be the output?
a_dict = {'color': 'blue', 'fruit': 'apple', 'pet': 'dog'}
for key in a_dict:
print(key)
'blue'
'apple'
'dog'
color
fruit
pet
blue
apple
dog
'color'
'fruit'
'pet'
Which statement is true?
Parameters are global variables.
Any variable created inside a function can be used outside.
Any variable created inside a function cannot be used outside.
Can only send primitives (boolean, String, int, float) as parameters
class = "Python"
year = 2021
print(f'It is {2021} and I am in {class} class.')
What is the output?
Error: Can only send variables as placeholders
It is 2021 and I am in class class.
It is year and I am in class class.
It is 2021 and I am in Python class.
It is 2021 and I am in "Python" class.
What will be the value of last_jedi after the following code is run?
["kylo", "rey", "finn", "luke"]
["kylo", "rey", "finn"]
3
4
What will be the value of authors after the following code is run?
["Martin", "Rowling", "Tolkien"]
["Martin"]
["Rowling"]
["Tolkien", "Rowling", "Martin"]
What is the correct syntax to write a for loop to iterate through the list grades?
for variable:
for variable in grades
variable in grades:
for variable in grades:
True or False
A Python Dictionary has two components, a key and a value.
True
False
Each key/value pair in a dictionary is separated by this symbol:
/
,
:
;
Using the [] operator, you can add or modify items in a:
Stack
Queue
Dictionary
Set
Which data structure is immutable?
Set
Dictionary
Tuple
In Python, are dictionaries immutable?
True
False
Which of the following is not a numeric datatype?
Float
Integer
Complex Numbers
Strings
Which of the following datatype is denoted by the round brackets ()?
List
Boolean
String
Tuple
Is the Grubhub guy ugly?
Yes
Yes
Yes
Yes
