Question: Coding has to be in python language def gcd(m, n): while m % n != 0: oldm = m oldn = n m = oldn

Write a new method for the Fraction class called mixed () which

Coding has to be in python language

def gcd(m, n): while m % n != 0: oldm = m oldn = n

m = oldn n = oldm % oldn

return n

class Fraction:

def __init__(self, top, bottom):

self.num = top # the numerator is on top self.den = bottom # thedenominator is on the bottom

def __str__(self): return str(self.num) + "/" +str(self.den)

def simplify(self): common = gcd(self.num, self.den)

self.num = self.num // common self.den = self.den // common

def __add__(self,otherfraction):

newnum = self.num*otherfraction.den+ self.den*otherfraction.num newden = self.den *otherfraction.den

f = Fraction(newnum, newden) f.simplify() return( f )

# define the mixed() method below

def main(): print("Create at least 2 Fraction objects and testyour mixed() method below")

if __name__ == "__main__": main()

Write a new method for the Fraction class called mixed () which returns a string that writes out the Fraction in mixed number form. Here are some examples: f1 Fraction (1, 2) print (f1. mixed()) f2 = Fraction (3, 2) print (f2.mixed()) f3 = Fraction (5, 1) print (f3.mixed()) # should print "1/2" # should return "1 and 1/2" # should return "5" Do not remove any of the provided functions, or alter them in any way. They are being used by the auto- grader, and any change to the existing functions and methods in the class will probably cause the auto- grader to fail.

Step by Step Solution

3.46 Rating (153 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Python version 36 Python program to add and test the mixed method of Fraction class def gcdm n while ... View full answer

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!