Answered step by step
Verified Expert Solution
Question
1 Approved Answer
How would I fix my code to remove these two errors. The coding language is Python using a Wing 101 IDE. class Fraction: Purpose: This
How would I fix my code to remove these two errors. The coding language is Python using a Wing 101 IDE.
class Fraction: Purpose: This function constructs fraction when it is invoked when the object of Fraction is created Parameters: self - self object n - numerator d - denominator Returns: None def init__(self, n=None, d=None): if n is None and d is None: self.n=None self.d=None else: g=self.gcd(n,d) self.n=int(n/g) self.d=int(d/g) 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 Purpose: This function adds fractions. Parameters: self - self object 0 - passed object Returns: temp def_add__(self,0): temp=Fraction() temp.d=self.d*o.d temp.n=self.n*(temp.d/self.d)+o.n*(temp.d/o.d) if(temp.no): g=self.gcd(-temp.n, temp.d) else: g=self.gcd(temp.n, temp.d) temp.n=int(temp.n/g) temp.d=int(temp.d/g) return temp Purpose: This function subtracts fractions. Parameters: self - self object - passed object Returns: temp o 55 56 57 58 59 60 def __sub__(self,o): temp=Fraction() temp.d=self.d*o.d temp.n=self.n*(temp.d/self.d)-o.n*(temp.d/o.d) if(temp.no): g=self.gcd(-temp.n, temp.d) else: g=self.gcd(temp.n, temp.d) temp.n=int(temp.n/g) temp.d=int(temp.d/g) return temp Purpose: This function multiplies fractions. Parameters: self - self object 0 - passed object Returns: temp 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 def _mul__(self,o): temp=Fraction() temp.n=self.n*o.n temp.d=self.d*o.d if(temp.nStep 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