class Fraction(): def __init__(self, num, denom): self.num = num self.denom = denom def __lt__(self, other): return self.num * other.denom < other.num * self.denom def __gt__(self, other): return self.num * other.denom > other.num * self.denom def __str__(self): return str(self.num) + '/' + str(self.denom) def readData(fileName): """Generic data reading function: reads lines in a text file and splits them into lists""" data = [] with open(fileName) as f: for line in f.readlines(): data.append(line.split('/')) return data def cleanLine(line): """Converts a raw line list into an appropriate data format.""" return Fraction(int(line[0]), int(line[1])) def findSmallest(fracs): smallest = fracs[0] for f in fracs: if f < smallest: smallest = f return smallest def findLargest(fracs): largest = fracs[0] for f in fracs: if f > largest: largest = f return largest rawData = readData('fractions.txt') fractions = [cleanLine(line) for line in rawData] small = findSmallest(fractions) large = findLargest(fractions) print('The smallest fraction is ' + str(small) + '.') print('The largest fraction is ' + str(large) + '.')