Due Tuesday 17-Jan, at 10:00pm
hw1.py
file includes test functions to help you test on your own before
you submit to Gradescope. When you run your file, problems will be tested in order. If
you wish to temporarily bypass specific tests (say, because you have not yet completed
some functions), you can comment out individual test function calls at the bottom
of your file in main()
. However, be sure to uncomment and test everything together
before you submit! Ask a CA if you need help with this.isValidYearOfBirth(year)
which, given a
value year
, returns True
if it is an integer value that
represents a valid year of birth, False
otherwise. Keep in mind
that, according to Wikipedia, the oldest person was born in 1904.
getTheCents(n)
which takes a
value n
(which represents a payment in US dollars) as input and
returns the number of cents in the payment. If n
is
an int
, the function should return 0, as it has 0 cents; otherwise,
if it isn't a float, it should also return 0, because a non-number payment make no
cents (ha!). You can assume that n will have up to 2 decimal places.
For instance,
distance(x1, y1, x2, y2)
to
find the distance between two points. This function takes
four int
or float
values representing two points and
returns the distance between those points.circleIntersection(xa,ya,ra,xb,yb,rb)
that will take six values as input parameters. These values represent the
coordinates (xa,ya)
of the center of circle A, and the
radius ra
of A, followed by the
coordinates (xb,yb)
of the center of circle B, and the
radius rb
of B. Your function should return the number of
intersection points (only the number, not the points). There are 4 possible
cases:
The circles do not touch each other. This could be because one is contained in the other circle, or they are too far apart from each other. In these cases your function should return value 0.
The circles intersect at a single point: either they touch internally or externally. In these cases your function should return value 1.
The circles intersect at two points. Your function should return value 2.
The circles intersect at infinitely many points, i.e., they fully
overlap. Your function should return infinity. In Python you can represent
positive infinity as float(''inf'')
distance
function that you just
wrote in the first part to help you solve this problem. Remember to use
almostEqual
or math.isclose
(instead of ==) when comparing floats!
In this case, we've picked a shade of red (RGB: 255, 38, 0) and a shade of green (RGB: 0, 255, 34). The color that is in triadic harmony with this two is the one that completes an isosceles triangle with them on the color wheel, like so:
That third color ends up being a shade of blue (RGB: 36, 0, 255)
colorHarmony(rgb1, rgb2)
, which takes
two integers representing colors at the perimeter of the wheel encoded as just
described and returns the color in the wheel that forms a triadic harmony with
those two colors.colorHarmony(255038000, 255034)
returns 36000255 (note that 36000255 is the same integer value as 036000255, and the
leading zeros is just an output formatting choice that we make when printing the
value) colorHarmony(255255, 255000000)
returns 128000255, although the
color 128255000 is also a valid solution. rgbToAngle(rgb)
to find the angle at which the RGB color lies.
angleToRGB(a)
to convert the angle to the RGB color.