View the step-by-step solution to:

Question

# I need help creating a fraction calculator based on the following python templates. />import equationdef main():  equ = equation.Equation()  again = 'y'  while again != 'q':    equ.read_equation()    frac = equ.compute_equation()    print(frac)    again = input('Another equation?: (q to quit)')main()class Fraction:  # constructor for Fraction  # default  def __init__(self, n=0, d=1):    # set private numerator & denominator fields and reduce the fraction  def __str__(self):    # return a string of how the fraction should look  def reduce(self):    #code to reduce itself based on the gcf method  def add(self, other):    result = Fraction()    # adds self and other    return result  def mult(self, other):    result = Fraction()    #multiplies self and other    return result  def div(self, other):    result = Fraction()    #divides self and other    return result  def sub(self, other):    result = Fraction()    #subtracts self and other    return result  def gcf(self, num1, num2):    # returns greatest common factor of num1 & num2import fractionclass Equation:  def __init__(self, f1 = fraction.Fraction(), f2 = fraction.Fraction(), op=''):    #sets data fields to the parameters if values are given  def __str__(self):    # returns string how it should look  def read_fraction(self, equ):    num = 0    i = 0    while equ[i] in ['0','1','2', '3', '4','5','6','7','8','9', '10']:      num = num * 10 + int(equ[i])      i += 1    # Remove the / character    equ = equ[i+1:]    i = 0    denom = 0    while equ[i] in ['0','1','2', '3', '4','5','6','7','8','9', '10']:      denom = denom * 10 + int(equ[i])      i += 1    frac = fraction.Fraction(num,denom)    return frac, equ[i:].lstrip()  def read_equation(self):    inputed_equ = input()    inputed_equ += ' '    frac1, inputed_equ = self.read_fraction(inputed_equ)    oper = inputed_equ[0]    inputed_equ = inputed_equ[1:].lstrip()    frac2, inputed_equ = self.read_fraction(inputed_equ)    self.__frac1 = frac1    self.__frac2 = frac2    self.__oper = oper  def compute_equation(self):    #returns fraction of computed equationSample input/output:1/2 + 1/43/4Another equation?: (q to quit)y2/3 * 5/65/9Another equation?: (q to quit)y2/1 - 3/45/4Another equation?: (q to quit)y4/1 / 1/28/1Another equation?: (q to quit)q

### Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

• ### -

Study Documents

Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

Browse Documents