Consider the following dictionary:
dict = { 'aardvark' : 'anthony', 'buffalo' : 'boris', 'zebra' : 'zelda' }
What would be the out of the following:
dict['aardvark']
'anthony'
What is the out of the following?
>>>a[100, 30, 20]
>>>a
100, 30, 20
In the following code, var1 is a(n)
def myFunction(var1)
var1 is a parameter
What is wrong with the following function?
def addOne(number): print number + 1
Everything is one line / there is no block indentation.
What would be the output of the following?
False
Can len() be used with tuples? If so, why would you use it?
Yes, it would tell you the number of items in a tuple.
True or False:
each key in a dictionary must be unique
True
What is the output of the following?
>>>a[100, 30, 20]
>>>a[2]
20
What is the maximum number of tasks a good function should generally complete for you?
1 task
What word would you use to describe the following?
question = ('apple', 'banana', 'cherry')
This is a tuple
What programming paradigm describes this method of showing an image?
pic.show()
object oriented
If you were using a sequential search for “date”, how many items in the following list would your code need to look at?
[“banana”, “date”, “cherry”, “apple”]
2
True or False:
Each key must be of a mutable type.
False, each key in a dictionary must be an immutable type.
Describe the code needed to set a list variable a that would store the values 100 and 20
>>> a[100, 20]
What is wrong with the following function, and why?
def countDown():
while a > 1:
print a
a = a – 1
Variable a is never defined - we need to Prime the Pump.
Which operator would be completed last in the following expression?
a * b / d + e / f
+
What is the name for an immutable ordered collection of characters?
a string
White on the board the line of code that would give us access to a library of tools that would allow us to read data from a website.
import urllib
Given the following dictionary, could you change Boris' first name to Bob? If so, how would you do this?
question = { "Aardvark" : "Anthony" , "Buffalo" : "Boris"}
Yes!
question[“Buffalo”] = “Bob”
Suppose you are using a binary search for the following list:
['bunny', 'cat', 'dog' ,'mouse']
What would be the first item you look at during your search?
dog
When using the style of software development that used for part 1 of project 4, what is the first function you should write for a program that will check the current weather in Boston?
A test function ex: test_checkWeather()
Write in one single line, a statement that would define a = 1, b = 2, and c = 3
a, b, c = 1, 2, 3
Could anything be done to make this line of code more efficient? If so, write it on the explain what you would change to make this as simple as possible:
if (a > b) == True and (b > a) == False:
if a > b:
Suppose I wanted to print “[fruit_name] is delicious!” for each fruit in the following list:
[“banana”, “date”, “cherry”, “apple”]
Which operation would be most appropriate: apply, filter, map, or reduce?
For double points, explain all three other operations!
map
Consider the following dictionary:
dict = { 'aardvark' : 'anthony', 'buffalo' : 'boris', 'zebra' : 'zelda' }
What would be the output of:
dict.keys()
['aardvark', 'buffalo', 'zebra']
What would be returned from the following statements?
number_list = range(-5, 5)
less_than_zero = list(filter(lambda x: x < 0, number_list))
print(less_than_zero)
[-5, -4, -3, -2, -1]
What would question(100) return given the following function??
def question(x):
if x == 5:
return 5
else:
return question(x - 5)
5
Write on the board a dictionary represented by the variable name dict, which contains two people:
Anthony Aardvark and Boris Buffalo
All or nothing, your syntax must be perfect.
{ "Aardvark" : "Anthony" , "Buffalo" : "Boris"}
Write the first line of an example of indefinite iteration, and explain how this is different from definite iteration.
While i > 1 :
This is different from definite iteration, which might be something like
for i in range (0,10):
If you were to sort the following list using the bubble sort method, what would your list look like after the first pass of sorting?
[“banana”, “date”, “cherry”, “apple”]
[“banana”, “cherry”, “apple”, “date”]