Quiz 2 Information
Quiz details
-
Quiz 2 will be held on Thursday 5/29, 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
quiz2.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 2, modules 3 and 4.
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.
The quiz will focus on the material that we have discussed in class during Week 1, i.e., modules 1 and 2. You must be familiar with concepts and syntax that were introduced in the pre-class videos, in-class discussion, or on the problem sets even if they were not covered in the videos or readings, specifically including:
-
Recursive functions with numeric data/results
-
Recursive function that process a sequence (e.g., string or lists)
-
Recursive functions that generate a sequence (e.g., string or list)
-
Recursive functions that process 2 sequences (e.g., string or list) at a time
-
Binary number conversions, bitwise operations, and bitwise add.
You also are expected to remember everything that was including in quiz 1, e.g., writing functions, arithmetic, decision statements, etc.
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
quiz2
tag).
Additional practice problems
-
What is printed by the following working Python program?
def mystery(x): print('x is', x) if x < 1: return 2 else: p = 6 - mystery(x - 1) print('p is', p) return p y = mystery(3) print('y is', y)
-
Write a function
count_ones(s)
that takes in a strings
of'0'
s and'1'
s and returns the number of'1'
s in the input. Use recursion. -
Write a function
swap_bits(s)
that takes in a strings
of'0'
s and'1'
s and returns a string in which each bit ins
has been swapped/replaced with the other bit. For example,swap_bits('101011')
should return'010100'
. Use recursion. -
Write a function
count_transitions(s)
that takes in a strings
of'0'
s and'1'
s and returns the number of times there is a transition from a'0'
to a'1'
or vice-versa in that input string. For example,count_transitions('1110110000')
should return3
. Use recursion. -
Write a function
abs_values(values)
that takes a list of integersvalues
and returns a new list containing the absolute values of each element invalues
. For example,abs_values([3, -4, 5, -6, 7])
will return[3, 4, 5, 6, 7]
. Use recursion. -
Write a function
join(strings, separator)
which takes a list ofstrings
and aseparator
(a string), and produces a result that is a string containing all of the elements in the list, separated by theseparator
. For example:join(['the','long','and','winding','road'], ' ')
would return'the long and winding road'
(note the lack of trailing space). Use recursion.