Advertisement
the_austria

times.py

Oct 20th, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. from sys import argv
  2.  
  3. class time(object):
  4.   def __init__(self,time):
  5.     self.h=time[0]
  6.     self.m=time[1]
  7.     self.s=time[2]
  8.   def addTime(self,other):
  9.     self.m+=(self.s+other.s)//60
  10.     self.s=(self.s+other.s)%60
  11.     self.h+=(self.m+other.m)//60
  12.     self.m=(self.m+other.m)%60
  13.     self.h+=other.h
  14.   def __str__(self): #string representation
  15.     return "%d:%d:%d" % (self.h,self.m,self.s)
  16.  
  17. def strToTime(str):
  18.   str=str.split(":")
  19.   for a in range(0,len(str)):
  20.     str[a]=int(str[a])
  21.   return str
  22.  
  23. name, t1, t2 = argv
  24.  
  25. time1=time(strToTime(t1))
  26. time2=time(strToTime(t2))
  27. time1.addTime(time2)
  28. print(time1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement