Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

image text in transcribedimage text in transcribed

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.n= 0.n/o.d: return True else: return false Purpose: This function checks if a fraction is less than another fraction. Parameters: self - selfl object 0 - passed object Returns: True or False 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 def it__(self,0): if self.n/self.d o.n/o.d : return True else: return False Purpose: This function calculates the greatest common divisor of the numerator and denominator Parameters: self - self object a - first arguement for god b - second arguement for god Returns: self def ged(self, a,b): if a == 0 : return b; if b==0 : return a if a==b: return a; if a>b: return self.gcd(a-b,b) return self.gcd(a,b-a) 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 Purpose: This function prints a string. Parameters: self - self object Returns: string def str__(self): return str(self.n)+'/'+str(self.d) Purpose: This function gets the numerator. Parameters: self - self object Returns: self def num(self): return self.n Purpose: This function gets the denominator. Parameters: self - self object Returns: self def denom(self): return self.d Test: print(ab, a=b, a==a, b!= b) Setup a = Fraction(-1,2) b = Fraction(1,1) Fatal error An error occurred while preparing to call the function. Test: print(a,b,c,d) Setup a = Fraction(1,-2) b= Fraction(-1,-2) C = Fraction(0,4) d = Fraction(0, -3) Fatal error An error occurred while preparing to call the function

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Upgrading Oracle Databases Oracle Database New Features

Authors: Charles Kim, Gary Gordhamer, Sean Scott

1st Edition

B0BL12WFP6, 979-8359657501

Students also viewed these Databases questions