Our final lab will be a pairs programming lab.

We will be implementing various methods in the Fractions class I introduced in class, to be assigned at lab time. Post your solutions (method by method) in the forum just below this entry in moodle.

Here is the base code:

class Fraction:


    def __init__(self, top, bottom):


        self.num = top        # the numerator is on top

        self.den = bottom     # the denominator is on the bottom


    def __str__(self):

        return str(self.num) + "/" + str(self.den)


    def getNum(self):

        return self.num


    def getDen(self):

        return self.den


    def times(self,aFrac):

        result = Fraction(self.num*aFrac.getNum(),self.den*aFrac.getDen())

        return result

myfraction1 = Fraction(3, 4)

myfraction2 = Fraction(2, 3)


print(myfraction1.times(myfraction2))


Last modified: Tuesday, October 15, 2019, 1:08 PM