Question: In Python Step One Create a class called Fraction (exact spelling and capitalization) in a file called Fraction.py (exact spelling and capitalization) that has instance

In Python

In Python Step One Create a class called Fraction (exact spelling and

Step One Create a class called Fraction (exact spelling and capitalization) in a file called Fraction.py (exact spelling and capitalization) that has instance variables for numerator and denominator (both integers). Step Two Add a method that reduces the fraction to lowest terms by dividing the numerator and denominator by their greatest common divisor. Use the Euclid algorithm to find the GCD. You can code it iteratively or recursively. (Your class should not print anything, unless you are doing this temporarily for debugging purposes, and remove it before submitting the final version. It makes no sense for a fraction to print.) Step Three Implement the_str_method to your Fraction class, so that a Fraction object can be printed. It should be printed in lowest terms. Step Four Implement the_add__magic method to do addition of two Fractions. Step Five Run the exact main program shown here for your class. The correct output for some sample input is shown on the next page. You do not need to turn in this main program, but your Fraction class should work with it. Turn in only your Fraction.py file. import Fraction while True : try: n, d = map(int, input ("Enter numerator and denominator for first fraction:").split()) if d = 0 raise ValueError f1 = Fraction. Fraction (n,d) n, d = map (int, input ("Enter numerator and denominator for second fraction:").split()) if d -- 0: raise ValueError f2 = Fraction.Fraction (n,d) f3 = fl + f2 print (f1, " + ", f2," = ",13) except ValueError: print ("bad input, please try again.")

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 Databases Questions!