Comparison
A sketchy use-case
Often, as we saw in the last lesson, we need to make choices depending on whether a number is larger than another. For example, let's say we have two test grades, and . Whoever got the higher test grade get five extra credit points for superb performance.
In Python, this would look something like the following.
def applyExtraCredit(x: float, y: float) -> tuple[float, float]:
return ( (x+5 if isLarger(x,y) else 0) + (x if not isLarger(x,y) else 0),
(y+5 if isLarger(y, x) else 0) + (y if not isLarger(y, x) else 0))
# There is definitely a better way to do this using python, but
# the above code models what we'll be doing using math.
Defining a comparison function
In order for this to work, we'll need a boolean function that returns whether or not .
We can test if is positive. If it is, then we can be sure that .
Luckily, we have a function for that already which we derived in the previous lesson:
So now, we just need to plug in to this function, and we will get our answer.