class Interval:
def __init__(self, hours=0, minutes=0, seconds=0):
self.hours = hours
self.minutes = minutes
self.seconds = seconds
self.total_seconds = 60*60*self.hours + 60*self.minutes + self.seconds
def __str__(self):
self.init_str = "{}:{}:{}".format(self.hours, self.minutes, self.seconds)
return self.init_str
def output(self, result):
self.result_hours = self.result // 3600
self.result_minutes = (self.result - self.result_hours*3600) // 60
self.result_seconds = self.result - self.result_hours*3600 - self.result_minutes*60
self.message = "{}:{}:{}".format(self.result_hours, self.result_minutes, self.result_seconds)
return self.message
def __add__(self, other):
self.result = self.total_seconds + other.total_seconds
return self.output(self.result)
def __sub__(self, other):
self.result = self.total_seconds - other.total_seconds
return self.output(self.result)
def __mul__(self, other):
self.result = self.total_seconds * other
return self.output(self.result)
fti = Interval(21,58,50)
sti = Interval(1,45,22)
try:
if isinstance(fti, Interval) and isinstance(sti, Interval):
print("First Time Interval:\t\t", fti)
print("Second Time Interval:\t\t",sti)
print("The result of (fit + sti):\t", fti + sti)
print("The result of (fti - sti):\t", fti - sti)
print("The result of (fti * 2):\t", fti * 2)
else:
raise TypeError
except:
print("TypeError")
Created
January 8, 2021 11:24
-
-
Save akirap3/34423d55baef68949dc385d1d772e65d to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment