Quiz 5 Information
Quiz details
-
Quiz 5 will be held on Monday 6/8 , 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 5 and problem set 5. 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
-
List comprehension
-
ASCII encoding/decoding
-
Optimizing a list of choices
You also are expected to remember everything that was including in previous modules, e.g., writing functions, arithmetic, decision statements, recursion, 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
quiz5tag).
Additional practice problems
-
Evaluate the following:
a.
'a' in 'backache'b.
[1, 2, 3] + [[11, 13, 12][1]] + [22, 33, 44, 55][1:]c.
[3 for x in range(6)]d.
[2*y + 1 for y in [1, 3, 5, 7]]e.
[x for x in range(3, 10) if x % 2 == 0]f.
[len(w) for w in ['Go', 'Terriers']] -
Write a function
count_occurences(x, values)that uses a list comprehension to process a list ofvaluesand counts how many times the elementxoccurs 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 dividenevenly. For example,num_divisors(42)should return8, because 1, 2, 3, 6, 7, 14, 21, and 42 are all divisors of 42. Use a list comprehension. -
Write a function
most_divisors(lst)that takes in a list of integerslstand returns the integer from that list with the most divisors. Use the abovenum_divisors(n)function in order to find the number of divisors for any integern.For instance,
most_divisors([2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])should return12.Use the list-of-lists optimization technique.
-
Write a function
longest_string(lst)that takes in a list of stringslstas input and returns the longest string from that list. For example,longest_string(['short', 'longer', 'sesquipedalian'])should return'sesquipedalian'.Use the list-of-lists optimization technique.
-
Write a function
most_of_letter(words, letter)that takes in a list of stringswordsand a characterlettteras input and returns the word from that list that has the most occurrences of the characterletter.For example,
most_of_letter(['short', 'longer', 'sesquipedalian'], 't')should return'short', since it has the most occurrences of the lettert.Use the list-of-lists optimization technique.