CMU 15-110 Fall 2018: Principles of Computing
Homework 2 (Due Tuesday 11-Sep at 8pm)
- Team vs Solo:
This hw has two parts -- a team hw, which is richly collaborative, and a solo hw, which is not collaborative but entirely solo (though of course with extensive supports by our TA's and course faculty). Please see the syllabus for details. These two parts are weighted equally in computing your hw1 score. - How-To Video:
To start this hw, first watch this helpful how-to video: - Starter code:
Next, download this file: hw2.py Then, edit that file you downloaded! - What to Submit (to Autolab):
When you think have solved the exercises, you can submit the edited version of your hw2.py file to Autolab. When you do, be sure to check the autograder's results! The autograder will grade some, though not all, of your submission. Check those results. If you did not get all the credit, you should try to fix your bugs and resubmit your fixed hw2.py file. - Do not leave this to the last moment:
Submitting to Autolab, and making sense of the autograder's output, can take some getting used to. Do not leave this to the last moment! Start early, submit early, and be done early. Easily your best approach! - Use your resources wisely!
Remember, the TA's have office hours every day, so go there and get some help! Today is a great day to do that! - Solo means solo (with tons of supports, of course!)
Do not help others with their solo hw, and do not ask others for help (including not asking on websites, etc). If you do need help, that's what TA's (and faculty) are here for! And, as just noted, they have office hours literally every day, plus they are on piazza every day! Plus, they are very happy to help. So: let them! If you need help, go to OH, use piazza, but work with the TA's (and faculty!) and get any help you need.
Team Hw2
- This part of the hw is team-based and collaborative.
- Here are the topics and activities we covered:
- Luis von Ahn's TedX talk
- Collaborative Code Tracing
- Collaborative Coding (nearestBusStop)
- Collaborative Creative Fun (madLibs and interactiveFiction)
- CS Academy Pictionary
Solo Hw2
- This part of the hw is solo and not collaborative. See the syllabus for details.
- eggCartons [25 pts]
Hint: This function is similar tofabricYards
from recitation! That function is also in the week2-practice problems, and here is a video explaining how to write it:
Write the functioneggCartons(eggs)
that takes a non-negative integer number of eggs, and returns the number of egg cartons required to hold that many eggs (given that each egg carton holds one dozen eggs, and you cannot buy fractional egg cartons). Be sure your function works for multiples of 12, including 0. Here are some test cases (that are already included in the the starter file for you):def testEggCartons(): print('Testing eggCartons()... ', end='') assert(eggCartons(0) == 0) assert(eggCartons(1) == 1) assert(eggCartons(12) == 1) assert(eggCartons(13) == 2) assert(eggCartons(24) == 2) assert(eggCartons(25) == 3) print('Passed.') - circlesIntersect [25 pts]
Write the functioncirclesIntersect(x1, y1, r1, x2, y2, r2)
that takes 6 numbers (ints or floats) -- x1, y1, r1, x2, y2, r2 -- that describe the circle centered at (x1,y1) with radius r1, and the circle centered at (x2,y2) with radius r2, and returnsTrue
if the two circles intersect andFalse
otherwise.
Hints:- Two circle intersect if the distance between their centers is not larger than the sum of their radii (do you see why?).
- You almost surely will want to use the
distance
function we wrote in recitation as a helper function here. Here is a helpful video on how to write that function:
- getTaOfficeHours [15 pts]
Hint: This function is similar togetFacultyOfficeHours
from the week2-practice problems!
At the time this was written, the TA's for 15-110 have office hours for 4 hours on Mondays, and 2 hours every other day, except not at all on Thursdays or Fridays. With this in mind, write the functiongetTaOfficeHours(day)
that takes a day (as a 3-character string, so 'Mon' for Monday), and returns the number of TA office hours for that day. You may assume the day is a legal day (so, one of 'Mon', 'Tue', 'Wed',...). - getAllOfficeHours [10 pts]
Hint: You will want to use bothgetTaOfficeHours
andgetFacultyOfficeHours
for this exercise!
Write the functiongetAllOfficeHours(day)
that works like the previous function, only it returns all the office hours for that day, including both faculty and TA office hours. This function should include just one line that does nothing except return the sum ofgetTaOfficeHours
andgetFacultyOfficeHours
! - customMadLib() [25 pts]
First, study the madLibs example from this week's Case Studies. Then, inspired by that example, write your own custom MadLib in the functioncustomMadLib
that's provided for you in the hw2.py file. This should be your own invention, and definitely very different from the one you write in the team hw. Do not copy a MadLib from an online (or any other) source. Be original, be creative, have some fun. We are not expecting Pulitzer-Prize-winner prose, but we are expecting some thoughtful, fun, cleverness, at least a bit. So have some fun with this!
Note: this exercise is not autograded. TA's will manually grade it. - Bonus/optional: customInteractiveFiction [up to 5 pts]
This exercise is bonus and optional. This is just like the madLibs exercise, but now for interactive fiction. Based on the interactiveFiction example from this week's Case Studies, write your own custom interactive fiction in the functioncustomInteractiveFiction
that's provided for you in the hw2.py file. Again, be original, do not copy from an online (or any other) source. Have fun with this!!!