WorksheetsWeek 6 Quiz - Dictionaries/Functions/F-Strings
Total questions: 16
Worksheet time: 10mins
What is the difference between dictionaries and lists?
Dictionaries and lists have different syntax, but otherwise are the same
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.
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 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'
def info(name, age):
print(f'Name: {name} /nAge: {age}')
info(10, John)
What is the ouput?
Erorr: does not return anything
f'Name: John
Age: 10
Name: 10
Age: John
Error: name should be a string not an integer. age should be an integer not a string.
Name: John
Age:10
What is the output?
Error: can not assign value to variable
Error: can not call a function as a parameter
27
12
3 + myfunction(4,5)
Which statement is true?
Parameters are global variables.
Any variable created inside a function can be used outside.
Any variable created inside a function can not be used outside.
Can only send primitives(boolean, String, int, float) as parameters
Leo wants to create a function that will roll a dice.
Which is the correct function definition header?
def dice roll( ) :
define function(diceroll):
def dice_roll():
def dice_roll()
def dice_roll[]
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.
How can I add more pairs into a dictionary dict?
dict.add('hey':'hi')
dict.update('hey','hi')
dict.append('hey','hi')
dict['hey'] = 'hi'
What is the output of the following code?
dict1 = {"key1":1, "key2":2}
dict2 = {"key2":2, "key1":1}
print(dict1 == dict2)
True
False
Error: can not compare dictionaries
Error: can only compare keys or values not both
Which one is false about functions?
It is reusable.
It avoids repetition.
It makes the code cleaner and organized.
It is meant to be used once.
Trick question!
What is the value of x?
Value inside function: 10
Value outside function: 20
Value inside function: 20
Value outside function: 10
Value inside function: 10
Value outside function: 10
Value inside function: 20
Value outside function: 20
What is the output?
def random(x,y):
return "hi"
sum = x+y
return sum
random(6,5)
30
11
hi
hi
11
hi
30
A student is writing a function to add the values in a dictionary of city populations (in thousands).
Which of the following situations is a dictionary the best data type to store information?
To store weekly ocean temperatures in a single ocean
To keep track of which books each library member has checked out
To track the highest score in a video game
Storing the shared letters between two words
