class Time(): def __init__(self,h,m): self.hours = h self.minutes = m def __add__(self,other): m = self.minutes + other.minutes h = self.hours + other.hours if m > 60: m -= 60 h += 1 return Time(h,m) def __str__(self): return str(self.hours)+" hours and "+str(self.minutes)+" minutes" sum = Time(0,0) with open("times.txt") as f: for line in f.readlines(): txt = line.split() sum = sum + Time(int(txt[0]),int(txt[1])) print(str(sum))