Quiz 4 Information
Quiz details
-
Quiz 4 will be held on Thursday 6/12, at a time that you will schedule with your facilitator (links below).
-
You will have 15 minutes for the quiz including writing and testing your code, and submission to Gradescope.
-
Expect 2 short questions. Each will ask you to write a function to solve a problem.
-
This quiz is closed notes/closed books, and without any use of reference materials.
-
There are some sample/pratice questions at the bottom of this page.
Quiz Logistics
-
The quiz will be a live proctored quiz conducted over Zoom.
-
You will meet your facilitator over Zoom and initiate a screen share of your entire desktop. If you have multiple monitors, you must disconnect any secondary monitor before the quiz.
-
Your camera must remain on during the quiz.
-
The facilitators will record all Zoom quiz sessions.
-
-
Use this Calendly link to schedule a time to take the quiz with your facilitator:
-
You should take the quiz by yourself in a quiet room, without assistance from others and without using resources of any kind.
-
You may not communicate with anyone during the quiz. You must not discuss the quiz with classmates until the entire quiz window is closed. Any discussion creates an unfair advantage to students who take the quiz a later time.
-
Aside from the machine on which you are reading the quiz, you must turn off and put away all other electronic devices including your phone, tablets, headphones, etc.
-
You will use Spyder (or another IDE) to write and test your code. Before you begin, you should create an empty file named
quiz4.py
, and close all other Spyder windows (including the console if there is any previous activity). You may run test code and use the console at that time. -
Other than Zoom and Spyder, all other applications should be closed.
-
You may not use ChatGPT or any other AI tools to write solutions for this quiz.
-
Anyone using ChatGPT or other AI tools will receive an automatic grade of F in the course, without exception or the right to appeal.
-
The instructor reserves the right to conduct a separate one-on-one oral examination with any student to verify the student’s understanding of the material.
-
Material covered
The quiz will focus on the material that we have discussed in class during Week 4, modules 7 and 8.
You must be familiar with concepts that were introduced in the pre-class videos, in-class discussion, or on the problem sets that were not covered in the videos or readings.
Preparing for the quiz
-
One way to prepare is to review the videos and readings and class notes and make a summary of the key points in your own words. “Summarizing” the material in this way is a great way to ensure that you really understand the key concepts.
-
We also encourage you to do practice problems. Options include:
-
redoing the problems from the problem sets
-
additional practice problems (below)
-
-
When working on practice problems, try to come up with your answers on paper, rather than through a trial-and-error approach in Spyder or in another programming environment. This will be give you an experience that is similar to the one that you have during the quiz.
-
Feel free to post questions about the quiz on Piazza (using the
quiz4
tag).
Additional practice problems
-
Draw one or more memory diagram (similar to what we have seen in Python Visualizer) to illustrate the execution of the following Python program:
a = [1, 2, 3, 4] b = a c = a[:] a[3] = 5 b[1] = 7 c[2] = 9 print('a is', a) print('b is', b) print('c is', c)
In addition, write a few sentences that refer to your diagram(s) and that explain the result of the program.
-
Draw memory diagrams that demonstrate why we get different results from the following two Python programs:
### Program 1 ### def foo(a): a = 2 * a return b = [1, 2, 3] for i in range(len(b)): foo(b[i]) print('b is', b) ### Program 2 ### def bar(lst, i): lst[i] = 2 * lst[i] return b = [1, 2, 3] for i in range(len(b)): bar(b, i) print('b is', b)
In addition, write a few sentences that refer to your diagrams and that explain the difference in output.
-
Write a function
create_2d
that takes as input two integersheight
andwidth
, and that creates and returns a 2D list (i.e., a list of lists) with values that are the row number multiplied by the column number. For example:>>> create_2d(3, 5) [[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]]
-
Write a function
add_one
that takes an inputgrid
that is a 2D list (a list of lists). Your function should add 1 to each element ofgrid
, but it should not return anything. For example:>>> my_grid = create_2d(3, 5) >>> add_one(my_grid) >>> my_grid [[1, 1, 1, 1, 1], [1, 2, 3, 4, 5], [1, 3, 5, 7, 9]]
-
Consider the following dictionary:
restaurants = {"Giordano": "(773) 262-1313", "Leona": "(773) 267-7287", "The Village", "(312) 332-7005"}
Evaluate the following expressions, in order:
a.
restaurants["Leona"]
b.
restaurants["(773) 262-1313"]
c.
"Giordano" in restaurants
d.
"Kiltie" in restaurants
e.
list(restaurants.keys())
f.
for name in restaurants:
print(name)
g.
len(restaurants)
-
Write expressions do the following:
a. add the phone number “(262) 567-2648” for “Kiltie” to the dictionary
restaurants
.b. print out each of the
restaurants
names and phone numbers, one per line