CMU 15-112 Spring 2019: Fundamentals of Programming and Computer Science
Lab 1 (Due as part of hw1 on Sunday 20-Jan, at 5pm)
- Reminder: Lab problems must be solved collaboratively with at least one other student! List your collaborators!
- All other problems that are not explicitly marked COLLABORATIVE must be completed individually, as stated in the course syllabus.
- You should put the solutions to these problems in your hw1.py file. Follow these steps if you haven't started yet!:
- Create a folder named 'week1'
- Download both hw1.py and cs112_s19_week1_linter.py to that folder
- Edit hw1.py using Pyzo
- When you are ready, submit hw1.py to Autolab. For this hw, you may submit up to 20 times (which is way more than you should require), but only your last submission counts.
- Do not use string indexing, loops, lists, list indexing, or recursion this week.
- Do not hardcode the test cases in your solutions.
- Your hw1 file should contain answers to these problems (25pts) plus the hw1 problems released earlier this week (75pts)
- Lab participation [5pts]
You must attend your Friday lab session and work with at least one other student on the collaborative problems below. A TA will provide you with a link to record your attendance. Be sure not to leave before your attendance has been recorded! - LAB COLLABORATIVE Code Writing: distance(x1, y1, x2, y2) [5pts]
Write the function distance(x1,y1, x2, y2), which takes four int or float values representing two points and returns the distance between those points. You will need to use this function for the next problem! - LAB COLLABORATIVE Code Writing: isRightTriangle(x1, y1, x2, y2, x3, y3) [5pts]
Write the function isRightTriangle(x1, y1, x2, y2, x3, y3) that takes 6 int or float values that represent the vertices (x1,y1), (x2,y2), and (x3,y3) of a triangle, and returns True if that is a right triangle and False otherwise. You must also use distance(x1, y1, x2, y2) as a helper function (which you wrote in the previous problem).
Note: You do not need to rewrite your distance function, even if your new collaboration partner wrote it a different way! As long as your functions are correct, they will behave identically.
Note 2: Recall that we said to use math.isclose() (instead of ==) when comparing floats. Unfortunately, math.isclose apparently has incorrect behavior when comparing to 0. Therefore. we're now recommending that you use our own function, almostEqual, which you can find in the course notes. - LAB COLLABORATIVE Code Writing: roundPegRectangularHole(r, w, h) and rectangularPegRoundHole(r, w, h) [10pts]
For this problem, you will write two similar functions: roundPegRectangularHole(r, w, h) and rectangularPegRoundHole(r, w, h)
roundPegRectangularHole(r, w, h) returns True if a round peg with radius r can pass through a rectangular hole with width w and height h, and False otherwise.
rectangularPegRoundHole(r, w, h) returns True if a rectangular peg with width w and height h can pass through a round hole with radius r, and False otherwise.
Don't make this problem harder than it needs to be! Assume this is a 2D problem, as shown in the diagrams below. (i.e. assume the pegs and holes are infinitely long, and don't check if 3D rotations can cram a short peg through a thin slot, etc.)
A round peg of radius 1 can fit inside a square hole with side lengths of 3, so RoundPegRectangularHole(1, 3, 3) should return True!
A round peg of radius 1 can also fit inside a rectangular hole with side lengths of 2 and 3 (but just barely!), so RoundPegRectangularHole(1, 2, 3) should return True. (RoundPegRectangularHole(1.1, 2, 3) would return False, though, because the radius would be too big!)
A rectangular peg with side lengths of 2 can fit inside a circular hole with a radius of 1.5, so rectangularPegRoundHole(1.5, 2, 2) should return True.
If the circle has a radius of 1.5 while the rectangle has side lengths of 2 and 3, both roundPegRectangularHole(1.5, 2, 3) and rectangularPegRoundHole(1.5, 2, 3) should return False. It doesn't matter which is the peg and which is the hole; neither will fit!
Collaborative lab problems
NOTE: Lab problems are collaborative. You must work on lab problems with at least one other student! However, you must follow the collaboration rules as specified by the syllabus, and you must list your collaborators in the special collaboration functions above each solution. These functions (like distanceCollaborators() ) should be modified to return a string containing all of your collaborators' andrewIDs separated by commas. If you do not list any collaborators, Autolab will not grade your solutions, and you will not get credit for these problems. If you collaborated but did not list your collaborators, you may lose points and this may be considered an academic integrity violation.
#Here is an example collaboration function. It returns a single string.
#This person lists three collaborators!
def exampleCollaborators():
return "mdtaylor, krivers, acarnegie"
Remember to submit your solutions to Autolab as part of hw1.py! And remember to list your collaborators in your file!
If you finish early, consider working on the collaborative colorBlender problem from hw1!