Question: Exercise 4 . 3 ( fractions . py ) . Any fraction can be written as the division of two integers. You could express this

Exercise 4.3(fractions.py).
Any fraction can be written as the division of two integers. You could express this in Python as
a tuple (numerator, denominator).
For example, the fractions 1
2,10
7, and 499
10001 can be represented using the tuples (1,2),(10,7),
and (499,10001).
Write the following functions:
reduce(fraction) This function takes a fraction, reduces it, and returns the result. For example,
reduce((8,4)) should return (2,1). To reduce a fraction a/b, divide a and b by their
GCD. The result is (a/d)/(b/d). The math module comes with the math.gcd function.
add(fraction1, fraction2) Given two fractions as tuples, add them.
multiply(fraction1, fraction2) Given two fractions as tuples, multiply them.
divide(fraction1, fraction2) Given two fractions as tuples, divide them.
These functions should not use input() or print().
Write a small command-line interface such that the user running your script sees something
like this:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!