CMU 15-112: Fundamentals of Programming and Computer Science
Quiz 1 (20 minutes)
Quiz 1 frontmatter:
- You may do the questions in any order, and you may leave them incomplete and return to them later if you wish. HOWEVER, if you begin a free response question (where you can run python code) any viewed but unsubmitted CTs and multiple choice questions will automatically be submitted and locked (so that you cannot run the CT code in the free response editor).
-
You have a fixed time to answer all the questions.
- Watch the timer carefully!
- If you are locked out due to a security error, exit the breakout room to speak with the TA or faculty member on duty
- Plug in your phone and computer
- Turn on do-not-disturb on your phone and computer and make sure your phone won't go to sleep or remove you from the zoom call or turn off your camera.
- Your phone must be properly positioned as described below
- Other than your main monitor and your phone, you must not have any other computer monitors on, and no other phones/tablets/calculators/notes/other resources should be accessible.
- Follow all proctoring instructions exactly. Failure to adhere to proctoring policy may result in a zero on the quiz, and possibly a deduction from your semester grade based on severity.
- Any attempt to subvert, exploit, or misuse the testing environment (including attempts to access the raw content or investigate the underlying source code) will be considered a severe academic integrity violation, possibly leading to course failure or other significant penalties.
-
You may not ask questions during the quiz.
- If you are unsure how to interpret a problem, take your best guess.
- You may not leave the quiz and return, and you may not interact with anyone else (remotely or in person) except for the TAs or faculty until the quiz is submitted.
- You must not leave the full-screen testing environment at any time. If anything except the testing environment is visible on your screen, it will trigger a security error, and you will be locked out of your quiz / you may receive a deduction or a zero. Additionally, we will investigate whether this could be a matter of academic integrity.
-
All of these must be visible to your phone's camera at all times:
- All of your screen, and any other screens nearby
- Most of your desk
- Your mouse and keyboard
- Note: You must not block your screen with your head/arms/etc while taking the quiz
- You must not have any other computer monitors on, and no other phones/tablets/calculators/notes/other resources should be accessible.
- If you are locked out due to a security error, exit the breakout room immediately to speak with the TA or faculty member on duty. At their discretion, they may unlock the quiz and allow you to continue.
- When you finish a question, press the submit button to lock in your answer. You will not be able to return and change your answers after pressing submit. Once the allotted time elapses, the quiz will auto-submit with your current progress. See above for more details
- You may receive a deduction if this is due to a lack of preparedness
- Join Zoom on your computer instead.
- You MUST still position your phone to see the items listed above, and you MUST record a video of the entire quiz until your proctor releases you.
- We will not grade any section of the quiz that we did not receive full video for, and you may receive a zero.This is true even if your phone runs out of storage space.
- After the quiz, immediately upload this to Google Drive or Box or Dropbox and then send us a link.You must use one of these three services. If you email the video directly or upload it to another source, you will receive a zero.
- If we cannot access or view your video, or if you do not record one, we will give you a zero, so make sure your upload is successful. We must be able to view the video soon after the quiz, so please begin uploading immediately.
- When your upload is complete, fill out the tech fail form and copy in the link to your video. Do not send it by email unless we request it.
- If you submit your quiz before time is up, wait until everyone else finishes and your proctor gives you further instructions.
- Wait until your proctor dismisses you, and then please exit Zoom. You are done! Rejoin the lecture Zoom session on your laptop.
- If you are still in Zoom, exit the breakout room and speak with the TA/Faculty in the main room. Do not speak while in the breakout room.
- If you cannot immediately speak with a TA or professor, stop taking the quiz and fill out the tech fail form linked from the course website's forms?page. (Note: A security error is not a tech fail, unless you are unable to return to the testing environment without triggering another one. We may be able to address accidental security errors in certain circumstances, but only if they are immediately brought to our attention.)
- We will email you soon to resolve the issue.
(This quiz was given in the CS Academy quiz proctoring app on 7/12)
Quick Reminders:
During the quiz
You must use your phone to join the proctored Zoom meeting. If you cannot join Zoom on your phone:
After the quiz
For any tech fails (laptop or internet stops working, etc.):
1. True/False [4 points]
Write only the whole word "True" or "False" (and not just T or F).
I understand that it is an Academic Integrity Violation to discuss/message/read/share anything at all about this quiz with any other 112 student, regardless of which lecture they attend, until the day after the quiz is taken (so, tomorrow). Hint: your answer had better be True!
2. True/False [4 points]
Write only the whole word "True" or "False" (and not just T or F).
The following line of code will crash:
print((9 // 7 == 2) or (2 / 0 == 1))
3. Multiple Choice [4 points]
Write only the letter of your answer.
Which of the following is NOT a built-in Python data type?
def
int
str
boolean
float
4. Multiple Choice [4 points]
Write only the letter of your answer.
Which of the following is NOT a part of the 15-112 style guide?
Use clear, concise, and informative comments
Make sure each function includes an explicit return statement
Do not include unused code
Line length should not exceed 80 characters
Use helper functions to break down large programs
5. Code Tracing [10 points]
What does the following code print?
def f(x):
return 3 * x - 2
def g(x):
return f(x + 3)
def ct1(x):
print(f(x - 2))
x -= 2
print(g(x))
x %= 4
return f(g(x) % 6) // 2
print(3 + ct1(4))
6. Code Tracing [10 points]
What does the following code print?
def ct2(m):
x = 1
while x < 5:
x += 2
print('x = ', x)
for y in range(m, m+2):
print('y = ', y)
x += y
return x
print(ct2(2))
7. Free Response: largestPerfectSquare(n) [32 points]
Write the function largestPerfectSquare(n) that takes a non-negative int n and returns the largest perfect square that is no larger than n. (A perfect square is any number whose square root is an integer, like 0, 1, 4, 9, 16, etc.)
For full credit, do not use any loops for this problem! You do not need them here. (Solutions that use loops will lose 3 points)
Hint: This can be written using just one or two lines of Python.
Note: We have included almostEqual and roundHalfUp, but this does not mean you need them.
######Helpers######### def almostEqual(d1, d2, epsilon=10**-7): #helper-fn return (abs(d2 - d1) < epsilon) #(This works the same as the one you've seen before) def roundHalfUp(d): #helper-fn sign = 1 if (d >= 0) else -1 d = abs(d) n = int(d) if (d - n >= 0.5): n += 1 return sign * n ###################### def largestPerfectSquare(n): return 42 def testLargestPerfectSquare(): print("Testing largestPerfectSquare...", end="") assert(largestPerfectSquare(5) == 4) assert(largestPerfectSquare(12) == 9) assert(largestPerfectSquare(24) == 16) assert(largestPerfectSquare(25) == 25) assert(largestPerfectSquare(2) == 1) assert(largestPerfectSquare(0) == 0) assert(largestPerfectSquare(2600) == 2500) print("passed!") testLargestPerfectSquare()
8. Free Response: nthTenlyPrime(n) [32 points]
Free Response: nthTenlyPrime(n)
We will say that a number is “tenly” (a made-up term) if the digits of the number add up to 10. So 1153 is tenly, but 153 is not. With this in mind, write the function nthTenlyPrime(n) that takes a non-negative int n and returns the nth number that is both tenly and prime. You should also write all the required helper functions.
You may use loops and anything else from this week's notes, but you may not use strings, lists, sets, dictionaries, recursion.
The first several tenly primes are: 19, 37, 73, 109, 127…
Note: We have included almostEqual and roundHalfUp, but this does not mean you need them.
######Helpers######### def almostEqual(d1, d2, epsilon=10**-7): #helper-fn return (abs(d2 - d1) < epsilon) #(This works the same as the one you've seen before) def roundHalfUp(d): #helper-fn sign = 1 if (d >= 0) else -1 d = abs(d) n = int(d) if (d - n >= 0.5): n += 1 return sign * n ###################### def nthTenlyPrime(n): return 42 def testNthTenlyPrime(): print("Testing nthTenlyPrime...", end="") assert(nthTenlyPrime(0) == 19) assert(nthTenlyPrime(1) == 37) assert(nthTenlyPrime(2) == 73) assert(nthTenlyPrime(3) == 109) assert(nthTenlyPrime(4) == 127) assert(nthTenlyPrime(8) == 307) print("passed!") testNthTenlyPrime()