61a-fa24-mt1
61a-fa24-mt1
INSTRUCTIONS
This is your exam. Complete it either at exam.cs61a.org or, if that doesn’t work, by emailing course staff with your
solutions before the exam deadline.
This exam is intended for the student with email address <EMAILADDRESS>. If this is not your email address, notify
course staff immediately, as each exam is different. Do not distribute this exam PDF even after the exam ends, as
some students may be taking the exam in a different time zone.
For questions with circular bubbles, you should select exactly one choice.
# You must choose either this option
# Or this one, but not both!
For questions with square checkboxes, you may select multiple choices.
2 You could select this choice.
2 You could select this one too!
You may start your exam now. Your exam is due at <DEADLINE> Pacific Time. Go to the next page
to begin.
Exam generated for <EMAILADDRESS> 2
Preliminaries
You can complete and submit these questions before the exam starts.
(a) What is your full name?
(d) Sign (or type) your name to confirm that all work on this exam will be your own. The penalty for academic
misconduct on an exam is an F in the course.
Exam generated for <EMAILADDRESS> 3
(b) (4.0 pt) Which of these whole lines appear somewhere in the printed output? Select all that apply.
2 1
2 1 2
2 1 2 3
2 1 2 3 4
2 3
2 5
2 5 6
2 6
2 7
2 8
2 None
2 None None
2 True
(c) (2.0 pt) What order do 1, 6, and 8 appear in the printed output? These numbers may appear as part of
longer lines. If a number appears twice, consider just the first occurence.
# 1 6 8
# 1 8 6
# 6 1 8
# 6 8 1
# 8 1 6
# 8 6 1
Exam generated for <EMAILADDRESS> 4
>>> final_digit(321) # 3 + 2 + 1 = 6
6
>>> final_digit(987) # 9 + 8 + 7 = 24, and 2 + 4 = 6
6
>>> final_digit(989898989) # The digit sum is 77, 7 + 7 = 14, and 1 + 4 = 5
5
"""
while n >= 10:
s = _______
(a)
_______:
(b)
n, s = n // 10, _______
_______ (c)
(d)
return n
(a) (1.0 pt) Fill in blank (a).
# 0
# n
# n % 10
>>> close(3756, 3456) and close(3456, 346) and close(346, 3456) and close(456, 56)
True
>>> close(5, 5) or close(3456, 3546) or close(3456, 36) or close(34, 3456) or close(345, 456)
False
"""
if m < n:
m, n = n, m
while m or n:
if _______:
(a)
m, n = _______
(b)
else:
return _______ or _______ # Hint: check here that just one change is enough
(c) (d)
return _______
(e)
(a) (1.0 pt) Fill in blank (a).
# m == n
# m // 10 == n // 10
# m // 10 == n
# m == n // 10
# m % 10 == n % 10
ii. (2.0 pt) Provide an alternate solution for blank (a) . This time, your solution must call compose
(defined below), and f may not be the operator of a call expression. In other words, you can’t write
f( in your answer. You may not write [ or if.
def compose(f, g):
"""Return a function that takes x and calls f on g of x."""
return lambda x: f(g(x))
Exam generated for <EMAILADDRESS> 10
def unshift(shifted):
"""Assume shifted is the return value of shifter(k) for some k.
No more questions.