Hi Guys,

I am currently working on the following project:

Write a PYTHON function that takes the time as three integer arguments (for hours, minutes, and seconds), and returns the number of seconds since the last time the clock “struck 12.” Use this function to calculate the amount of time in seconds between two times, both of which are within on 12-hour cycle of the clock.

Here is what I have done so far:

``````class Time:

def after(self, time2):
"Return true if this time after time2."
return self.convertToSeconds() > time2.convertToSeconds()

def convertToSeconds(self):
"Convert time to seconds."
return self.hours * 3600 + self.minutes * 60 + self.seconds

def increment(self, seconds):
"Increment time by seconds."
self.seconds += seconds
self.reduceTime()

def reduceTime(self):
while self.seconds >= 60:
self.seconds -= 60
self.minutes += 1
while self.minutes >= 60:
self.minutes -= 60
self.hours += 1

def showTime(self):
"Display time in 24-hour format."
print "%02d:%02d:%02d" % (self.hours, self.minutes, self.seconds)``````

NOW, I'm stuck and I have no idea how to continue with the code. Can anybody please help me with this project?Any help would be greatly appreciated!!! thanks a lot!!!

I do not understand class without init also push code before pasting code.

Write a PYTHON function that takes the time as three integer arguments (for hours, minutes, and seconds)

You are supposed to create a function, not a class, that takes three arguments/parameters. Your class doesn't take any arguments. You can take a look at functions here for a simple example.

You are making your life too complicated! You are almost there actually ...

``````def convertToSeconds(hours, minutes, seconds):
"Convert time to seconds."
return hours * 3600 + minutes * 60 + seconds

# give time as a (hours, minutes, seconds) tuple
time1 = (8, 30, 0)
time2 = (9, 36, 40)

# the * expands the tuple to hours, minutes, seconds
seconds1 = convertToSeconds(*time1)
seconds2 = convertToSeconds(*time2)

print(seconds1)
print(seconds2)

diff = abs(seconds1 - seconds2)

print(diff)

""" result >>>
30600
34600
4000
"""``````
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.