Get syntax error. Dont understand why - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Get syntax error. Dont understand why (/thread-18308.html) |
Clock\Calendar for my game [Renpy] - beLIEve - May-10-2019 Hello! I am looking for luck I have whole idea how should work my game but i stuck with simple things Try to learn but it is not undersatnd to me so my question is How to combine this two codes init python: class clock(object): def __init__(self, century = 19, year = 1999, month = 1, day = 1, hour = 8, minute = 0): self._century = century self._year = year self._month = month self._day = day self._hour = hour self._minute = minute def addtime(self, minutes, hours = 0, days = 0, months = 0, years = 0, centuries = 0): self._minute += minutes # add minutes self._hour += hours # add hours self._day += days self._month += months self._year += years self._century += centuries # add hours by floor division minute over 60 self._hour += self._minute // 60 # add days by floor division hour over 24 - make sure to do this after hour's been added self._day += self._hour // 24 self._month += self._day // 31 # Q Ok how to ? self._year += self._month // 12 # Q 372 days self._century += self._year // 100 # now we can clean up minutes and hours by using mod % self._minute = self._minute % 60 self._hour = self._hour % 24 self._day = self._day % 31 self._month = self._month % 12 self._year = self._year % 372 # Q how to 365? and 366? # use property to return formatted hour and minutes @property def century(self): # day as int return self._century @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:] default clock = clock() label start: while True: "Day: [clock.day] Time: [clock.hh]:[clock.mm]" $ 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 init python: weekdays = ("mon","tue","wed","thu","fri","sat","sun") class Date: def __init__(self): self.year = 2019 self.month = 2 self.day = 28 self.weekday = weekdays[3] def end_day(self): self.day += 1 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 # 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) I would like to get effect time control from upper code formatting from upper code weekdays and leap year counter from below If u think it easy for u to make it please do it because for me it is impossible Get syntax error. Dont understand why - beLIEve - May-13-2019 https://paste.ofcode.org/j9kWMQUP7cdi7Gn2jP28w Showing syntax in line 15 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 = 2019 self.month = 2 self.day = 28 self.weekday = weekdays[3] self.hour = 7 self.minute = 0 self.second = 0 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 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): 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:] @property def sz(self): season = seasons[season] return seasons=[season] def dt(self): daytime = daytimes[daytime] return daytimes[daytime] default clock = clock() label start: while True: "Day: [clock.day] Time: [clock.hh]:[clock.mm] [clock.sz] [clock.dt]" $ clock.addtime(15) "Date: [clock.day]/[clock.month]/[clock.year] Time: [clock.hh]:[clock.mm]" $ clock.addtime(44640) "Blow mind" return RE: Get syntax error. Dont understand why - ichabod801 - May-13-2019 You need a colon at the end of the line. RE: Get syntax error. Dont understand why - SnoopFrogg - May-13-2019 (May-13-2019, 12:46 AM)beLIEve Wrote:You're missing a colon as ichabod801 mentioned.def addtime(self , seconds , minutes , hours) RE: Get syntax error. Dont understand why - beLIEve - May-13-2019 TypeError: __init__() takes exactly 8 arguments (1 given) Soo i unbugged from missing colons and whatever it was after, and after, and after but this is too much for my knowledge or lack of her 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 = 2019 self.month = 2 self.day = 28 self.weekday = weekdays[3] self.hour = 7 self.minute = 0 self.second = 0 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 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:] @property def sz(self): season = seasons[season] return seasons[season] def dt(self): daytime = daytimes[daytime] return daytimes[daytime] default clock = clock() # 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 RE: Get syntax error. Dont understand why - SnoopFrogg - May-13-2019 (May-13-2019, 01:14 AM)beLIEve Wrote: TypeError: __init__() takes exactly 8 arguments (1 given) Is this your code? I tried running this in VS Code and there's a ton of problems. Have you tried using the debugger? Step in line by line. RE: Get syntax error. Dont understand why - beLIEve - May-13-2019 If you ask. No it is not my code. I tryieed to mix 2 working codes on one and i add my stuff you can see progress from 2 days The codes were provided as opensource. Here is my last topic https://python-forum.io/Thread-Clock-Calendar-for-my-game-Renpy The debugger comes from Renpy and pycharm but i am not good in this I have lack of knowledge but i still try RE: Get syntax error. Dont understand why - SnoopFrogg - May-13-2019 (May-13-2019, 01:41 AM)beLIEve Wrote: If you ask. If I'm not mistaken renpy is a different extension than a regular python program. I've only used renpy once but I'm sure there's documentation on how to use the debugger in renpy. RE: Get syntax error. Dont understand why - beLIEve - May-13-2019 Really. It is not the point that i use renpy because it should be clean python what i can implement there by init python: . The point is i fcuked up something in class clock but i dont understand classes after 6 books and 10 video turtoials about classes i dont get wtf. You guys you are my last hope Should show data not memory alloc and nbound method error - beLIEve - May-13-2019 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) |