(10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
# Reduce a rational number automatically reduces before it is printed out
def gcd(a, b): # Greatest Common Divisor
if b == 0:
return a
else:
return gcd(b, a % b)
class Rational:
def __init__(self, n, d):
self.numerator = n
self.denominator = d
def reduce(self):
g = gcd(self.numerator, self.denominator)
self.numerator = self.numerator // g
self.denominator = self.denominator // g
def __str__(self):
self.reduce()
return str(self.numerator) + '/' + str(self.denominator)
def main():
a = Rational(6, 8)
print(a)
main()