Due Tuesday 29-Aug, 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 1907.
numberOfPoolBalls(rows)
that takes a non-negative int
value, the number of rows, and returns another int value, the number of pool balls in that number of full rows. For example, numberOfPoolBalls(3)
returns 6. We will not limit our analysis to a "rack" of 15 balls. Rather, our pool table can contain an unlimited number of rows. Hint: you may want to briefly read about
Triangular Numbers. Also, remember not to use loops!
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,
isSymmetricNumber(n)
, which takes a value n
and returns True
if n
is a symmetric number and False
otherwise. Notes: The numbers can be arbitrarily large. For example, 444555666444555666 is a symmetric number.
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!
colorBlender(rgb1, rgb2, midpoints, n)
,
which takes two integers representing colors encoded
as just described, a non-negative integer number of
midpoints, and a non-negative integer n, and
returns the nth color in the palette that the tool
creates between those two colors with that many midpoints. If n
is out of range (too small or too large), return None
.colorBlender(220020060, 189252201, 3, 1)
returns 212078095