Python Forum
Get syntax error. Dont understand why
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get syntax error. Dont understand why
#1
Hello!
I am looking for luck Wall

I have whole idea how should work my game but i stuck with simple things Confused
Try to learn but it is not undersatnd to me so my question is Dodgy

How to combine this two codes Huh

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)
Rolleyes
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
Reply
#2
Exclamation 
https://paste.ofcode.org/j9kWMQUP7cdi7Gn2jP28w

Showing syntax in line 15 Wall

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
Reply
#3
You need a colon at the end of the line.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#4
(May-13-2019, 12:46 AM)beLIEve Wrote:
def addtime(self , seconds , minutes , hours)
You're missing a colon as ichabod801 mentioned.
Reply
#5
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
Reply
#6
(May-13-2019, 01:14 AM)beLIEve Wrote: 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

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.
Reply
#7
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-Cal...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
Reply
#8
(May-13-2019, 01:41 AM)beLIEve Wrote: 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-Cal...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

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.
Reply
#9
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. Dance
You guys you are my last hope
Reply
#10
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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  POST Syntax error amplay 0 1,297 Aug-07-2024, 02:43 PM
Last Post: amplay
  I dont understand on how to create a Bot that can read info on the screen aloud RaySuS777 0 1,023 Jun-19-2024, 10:02 AM
Last Post: RaySuS777
  is this really a syntax error? Skaperen 4 2,511 May-25-2024, 07:31 AM
Last Post: snippsat
  World Clock syntax error OscarBoots 1 1,730 May-03-2024, 05:20 AM
Last Post: snippsat
  Syntax error for "root = Tk()" dlwaddel 15 10,416 Jan-29-2024, 12:07 AM
Last Post: dlwaddel
Photo SYNTAX ERROR Yannko 3 2,037 Jan-19-2024, 01:20 PM
Last Post: rob101
  Syntax error while executing the Python code in Linux DivAsh 8 8,462 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Code is returning the incorrect values. syntax error 007sonic 6 4,147 Jun-19-2023, 03:35 AM
Last Post: 007sonic
  syntax error question - string mgallotti 5 3,593 Feb-03-2023, 05:10 PM
Last Post: mgallotti
  Syntax error? I don't see it KenHorse 4 3,770 Jan-15-2023, 07:49 PM
Last Post: Gribouillis

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.