Quiz 4 Information
Quiz details
-
Quiz 4 will be held on Wednesday 6/3 , 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 4 and problem set 4. 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 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 previous modules, 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
quiz4tag).
Additional practice problems
-
Consider the following recursive function:
def foo(vals): if vals == []: return [] if len(vals) == 2: return [vals[0]+ 1] foo_rest = foo(vals[:-1]) return [vals[-1]] + foo_rest
Trace the execution of the function call
foo([7, 6, 5, 3]). You may use any reasonable approach, but you must show all of the recursive function calls.What is returned from the function call
foo([7, 6, 5, 3])? -
Convert the decimal number
109to binary, showing your work. -
Convert the binary number
11001100to decimal, showing your work. -
Add the binary number
1100to0110. Show your work. -
Use recursion (no loops!) to write a function
find_multiples(lst, n)that takes a list of integerslstand an integernand returns the items fromlstthat are multiples ofn. For example:>>> find_multiples([4, 5, 9, 11, 21], 3) [9, 21] # 9 and 21 are multiples of 3
-
Write a recursive function
remove_char(c, s)that returns a new string with every occurrence of the charactercremoved. You may not use any built-in functions. Examples:remove_char(“l”, “hello world”) “heo word” remove_char(“a”, “banana”) “bnn” remove_char(“z”, “hello”) “hello” # no ‘z’ in “hello”
-
Write a recursive function
is_palindrome(s)that returnsTrueif the stringsis a palindrome (reads the same forwards and backwars) andFalseotherwise. For the purpose of this function, spaces should be ignored. Here are some examples:>>> is_palindrome("racecar") True >>> is_palindrome("hello") False >>> is_palindrome("taco cat") True >>> is_palindrome("never odd or even") TrueHint: think about base cases, and test those first! Hint: think about how you can test for spaces and skip them in your recursive step.