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
#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


Messages In This Thread
Clock\Calendar for my game [Renpy] - by beLIEve - May-10-2019, 08:52 AM
Get syntax error. Dont understand why - by beLIEve - May-13-2019, 12:46 AM
Should show data not memory alloc and nbound method error - by beLIEve - May-13-2019, 10:07 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  World Clock syntax error OscarBoots 1 155 May-03-2024, 05:20 AM
Last Post: snippsat
  Syntax error for "root = Tk()" dlwaddel 15 1,284 Jan-29-2024, 12:07 AM
Last Post: dlwaddel
Photo SYNTAX ERROR Yannko 3 432 Jan-19-2024, 01:20 PM
Last Post: rob101
  Syntax error while executing the Python code in Linux DivAsh 8 1,681 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Code is returning the incorrect values. syntax error 007sonic 6 1,267 Jun-19-2023, 03:35 AM
Last Post: 007sonic
  syntax error question - string mgallotti 5 1,358 Feb-03-2023, 05:10 PM
Last Post: mgallotti
  Syntax error? I don't see it KenHorse 4 1,319 Jan-15-2023, 07:49 PM
Last Post: Gribouillis
  Syntax error tibbj001 2 933 Dec-05-2022, 06:38 PM
Last Post: deanhystad
  I dont know why my function won't work? MehHz2526 3 1,215 Nov-28-2022, 09:32 PM
Last Post: deanhystad
  Something the code dont work AlexPython 13 2,315 Oct-17-2022, 08:34 PM
Last Post: AlexPython

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020