May-13-2019, 10:07 AM
init python: weekdays = ("mon","tue","wed","thu","fri","sat","sun") daytimes = ("midnight","night","dawn","morning","noon","afternoon","dusk","night") seasons = ("winter", "spring", "summer", "autumn") class clock(object): def __init__(self , year , month , day , weekday, hour, minute, second): self.year = year self.month = month self.day = day self.weekday = weekday self.hour = hour self.minute = minute self.second = second def addtime(self , seconds , minutes , hours): self.second += seconds self.minute += minutes # add minutes self.hour += hours self.minute += self.second // 60 self.hour += self.minute // 60 self.day += self.hour // 24 self.second = self.second % 60 self.minute = self.minute % 60 self.hour = self.hour % 24 self.weekday = weekdays[weekdays.index(self.weekday)-6] if self.month in (1,3,5,7,8,10,12): if self.day > 31: self.day = 1 self.month += 1 elif self.month in (4,6,9,11): if self.day > 30: self.day = 1 self.month += 1 #february in leap year else : # devide by 4 if (self.year // 4) == 0 : # devide by 100 if (self.year // 100) == 0 : # devide by 400 if (self.year // 400) == 0 : #leap year __d = 29 else: #normal year __d = 28 else: #devide by 4 - leap year __d = 29 else: #normal year __d = 28 if self.day > __d: self.day = 1 self.month += 1 if self.month > 12: self.month = 1 self.year += 1 def daytime(self, daytime, season): #("midnight","night","dawn","morning","noon","afternoon","dusk","night") if self.month in (12,1,2): self.season = seasons[0] if self.hour == 0: return daytime[0] if self.hour > 0 and self.hour < 7: return daytime[1] if self.hour > 7 and self.hour < 8: return daytime[2] if self.hour > 8 and self.hour < 11: return daytime[3] if self.hour == 12: return daytime[4] if self.hour > 13 and self.hour < 16: return daytime[5] if self.hour > 16 and self.hour < 17: return daytime[6] if self.hour > 17 and self.hour < 23: return daytime[7] if self.month in (3,4,5): self.season = seasons[1] if self.hour == 0: return daytime[0] if self.hour > 0 and self.hour < 5: return daytime[1] if self.hour > 5 and self.hour < 6: return daytime[2] if self.hour > 6 and self.hour < 11: return daytime[3] if self.hour == 12: return daytime[4] if self.hour > 13 and self.hour < 18: return daytime[5] if self.hour > 18 and self.hour < 19: return daytime[6] if self.hour > 19 and self.hour < 23: return daytime[7] if self.month in (6,7,8): self.season = seasons[2] if self.hour == 0: return daytime[0] if self.hour > 0 and self.hour < 4: return daytime[1] if self.hour > 4 and self.hour < 5: return daytime[2] if self.hour > 5 and self.hour < 11: return daytime[3] if self.hour == 12: return daytime[4] if self.hour > 13 and self.hour < 20: return daytime[5] if self.hour > 20 and self.hour < 21: return daytime[6] if self.hour > 21 and self.hour < 23: return daytime[7] if self.month in (9,10,11): self.season = seasons[3] if self.hour == 0: return daytime[0] if self.hour > 0 and self.hour < 5: return daytime[1] if self.hour > 5 and self.hour < 6: return daytime[2] if self.hour > 6 and self.hour < 11: return daytime[3] if self.hour == 12: return daytime[4] if self.hour > 13 and self.hour < 18: return daytime[5] if self.hour > 18 and self.hour < 19: return daytime[6] if self.hour > 19 and self.hour < 23: return daytime[7] # get weekdays def get_weekdays(self): if self.month < 3 : __m = self.month + 12 __y = self.year - 1 else : __m = self.month __y = self.year __weekday = ((__y+__y/4-__y/100+__y/400+(13*__m+8)/5+self.day) % 7) - 1 self.weekday = weekdays[__weekday] return weekdays[__weekday] #def return_date(self): # return unicode(self.year)+". "+unicode(self.month)+". "+unicode(self.day) @property def season(self): return self.season @property def sz(self): season = str(season[season]) return seasons[season] @property def daytime(self): return self.daytime @property def dt(self): daytime = str(daytimes[daytime]) return daytimes[daytime] @property def year(self): # day as int return self.year @property def yy(self): # minutes as mm. year = "0" + str(self.year) return year[-2:] @property def month(self): # day as int return self.month @property def mn(self): # minutes as mm. month = "0" + str(self.month) return month[-2:] @property def day(self): # day as int return self.day @property def dd(self): # minutes as mm. day = "0" + str(self.day) return day[-2:] @property def hour(self): # hour as int return self.hour @property def hh(self): # hours as HH. I'm not familiar enough with python to know if there's a shorter way to do this hour = "0" + str(self.hour) return hour[-2:] # Q what is doing this 2? @property def minute(self): # minute as int return self.minute @property def mm(self): # minutes as mm. minute = "0" + str(self.minute) return minute[-2:] @property def second(self): return self.second @property def ss(self): second = "0" + str(self.second) return self.second[-2:] # label start: # while True: # "Day: [clock.day] Time: [clock.hh]:[clock.mm] [clock.sz] [clock.dt]" # $ clock.addtime(15) # Q how to able add for ex months? Count? 60x24x31~~44640 # "Date: [clock.day]/[clock.month]/[clock.year] Time: [clock.hh]:[clock.mm]" # $ clock.addtime(44640) # Here Error why? # "Blow mind" # return[clock.day] and others show me memmory allocation not the data >< Why ??
After that i have error
unbound method addtime() must be called with clock instance as first argument (got int instance instead)