Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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
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