Coding has to be in python language def gcd(m, n): while m % n != 0: oldm
Question:
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()
Microeconomics An Intuitive Approach with Calculus
ISBN: 978-0538453257
1st edition
Authors: Thomas Nechyba