Question
Python Program 5 Fraction Calculator You can express a fraction as a tuple: (numerator, denominator). Write a fruitful function called add(x,y) that adds two fractions
Python
Program 5 Fraction Calculator
You can express a fraction as a tuple: (numerator, denominator). Write a fruitful function called add(x,y) that adds two fractions that are passed as tuples. Write a fruitful function called mpy(x,y) that multiplies two fractions that are passed as tuples. Write a main driver that repeatedly asks the user to input two fractions (as tuples) which then displays the sum and product of the two provided fractions. The program should loop until the user inputs a fraction (0, 0). Your program must not use lists anywhere; it must use tuples. Remember that to add two fractions a/b + c/d the sum is (ad + bc) / bd. So, 2/3 + 5/7 = (2x7 + 3x5) / (3x7) = (14+15) / 21 = 29/21 To multiply two fractions a/b x b/c the product is ab / cd. So, 2/3 x 5/7 = (2x5) / (3x7) = 10/21 Your answers must be in reduced form. That means there is no common divisor of the numerator and the denominator. For example, 11/22 reduces to 1/2 (the common divisor is 11). 7/9 already is in reduced form. Euclids Algorithm for find the greatest common divisor (gcd) of two integers is: def gcd(x, y): while y: x, y = y, x % y return x Run your program several times using different inputs sufficient to demonstrate that your program meets all the assignment requirements. Capture a screen shot of each run and paste them into an MS Word document. Place a caption above each image.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started