# Fraction - Initial skecth to be competed # # Author: Yotam Medini yotam.medini@gmail.com -- Created: 2006/September/29 # def str2nd(s): "Given string of the form 'nnnn/dddd' return (nnnn, dddd) or None" .... class Fraction: def __init__(self, n=0, d=1): self.n = n self.d = d def __str__(self): return "(%d/%d)" % (self.n, self.d) def strset(self, s): ok = True nd = str2nd(s) if nd == None: pass # ..... else: self.n = .... self.d = .... return ok def __add__(self, other): ... def __mult__(self, other): ... if __name__ == '__main__': # Test program import sys x1 = Fraction() x2 = Fraction() s1 = sys.argv[1] s2 = sys.argv[2] x1.strset(s1) x2.strset(s2) sys.stdout.write("x1+x2 = %s + %s = %s\n" % (x1, x2, x1 + x2)) sys.exit(0)