Quiz 3 Information
Quiz details
-
Quiz 3 will be held on Thursday 6/5, 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
quiz3.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 3, modules 5 and 6.
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
quiz3
tag).
Additional practice problems
-
Evaluate the following list comprehensions:
a.
'a' in 'backache'
b.
[3 for x in range(6)]
c.
[2*y + 1 for y in [1, 3, 5, 7]]
d.
[x for x in range(3, 10) if x % 2 == 0]
e
[len(w) for w in ['Go', 'Terriers']]
-
Write a function
count_occurences(x, values)
that uses iteration to process a list ofvalues
and counts how many times the elementx
occurs invalues
. For example:count_occurences([7, [7, 4, 7, 6, 8, 5])
would return 2, and,count_occurences([3, [7, 4, 7, 6, 8, 5])
would return 0. -
Write a function
num_divisors(n)
that returns the number of integers from 1 ton
(inclusive) that dividen
evenly. For example,num_divisors(42)
should return8
, because 1, 2, 3, 6, 7, 14, 21, and 42 are all divisors of 42.Try solving this 2 ways:
a. Use as list comprehension to produce the list of divisors of
n
, and then uselen(list)
to count the number of divisors ofn
.b. Use iteration and the accumulator pattern to count the number of divisors of
n
. -
Use the above
num_divisors(n)
function in order to write a functionmost_divisors(lst)
that takes in a list of integerslst
and returns the integer from that list with the most divisors. For instance,most_divisors([2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])
should return12
. -
Write a function
longest_string(lst)
that takes in a list of stringslst
as input and returns the longest string from that list. For example,longest_string(['short', 'longer', 'sesquipedalian'])
should return'sesquipedalian'
. -
Write a function
cycle(s, n)
that takes in a strings
of'0'
s and'1'
s and an integern
and returns the string in whichs
has shifted its last character to the initial positionn
times. For example,cycle('1110110000', 2)
should return'0011101100'
.Hint: use a loop