Quiz 3 Information
Quiz details
-
Quiz 2 will be held on Monday 6/1 , beginning promptly at 9:30am.
-
The quiz will be on paper, and you will be expected to write/explain some code that is similar to work you did in the problem set.
-
Expect 2 short questions.
You will have 20 minutes for the quiz including.
-
This quiz is closed notes/closed books, and without any use of reference materials. No computers, phones, AI glasses, or other electronic devices are permitted.
-
There are some sample/pratice questions at the bottom of this page.
Material covered
The quiz will focus on the material that we have covered in module 3 and problem set 3. 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
You also are expected to remember everything that was including in quiz 2, 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
quiz3tag).
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 stringsof'0's and'1's and returns the number of'1's in the input. Use recursion. -
Write a recursive function
sum_list(values)that returns the sum of all numbers in a list. You may not use any built-in functions. >>> sum_list([1, 2, 3, 4]) 10 >>> sum_list([5, -3, 2]) 4 >>> sum_list([]) 0 -
Write a function
swap_bits(s)that takes in a stringsof'0's and'1's and returns a string in which each bit inshas 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 stringsof'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 integersvaluesand 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 ofstringsand 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.