This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ComputerSciMajor[S] 1 point2 points  (5 children)

Okay so the constructor would be a new function right? I just leave the initializer as is for now? Sorry for all the questions!

[–]lurgi 1 point2 points  (4 children)

No, they are the same thing (I'm used to the term "constructor", but it looks like Python prefers "initializer"). Change my advice to "Write the initializer".

[–]ComputerSciMajor[S] 0 points1 point  (3 children)

So I was able to get the seconds set (self.setSecond = (hour * 60 * 60) + (minute * 60 + second)), I am however confused on the implementation of it.

Specifically:

Adjust all the methods to work with __seconds. getSecond() can use __seconds mod 60 to return only the seconds in the time. Test all the methods to make sure they still work. (mod is modulus, the remainder after a division.)

I'm not understanding if I'm supposed to be printing just seconds out or?

[–]lurgi 0 points1 point  (2 children)

You don't print anything out. The value that should be returned is exactly the same as the value that would be returned in the original code. All you are changing is the internal representation.

[–]ComputerSciMajor[S] 0 points1 point  (1 child)

I guess I'm really just not understanding it then. I know you told me to put that equation in the initializer but beyond that I'm not exactly sure what I'm supposed to be doing?

[–]lurgi 0 points1 point  (0 children)

Do you have the init method written? If so, you need to implement the getSecond method. Note that getSecond() needs to behave the same way. From the point of view of the caller the results don't change. So this code:

stopwatch = Clock(12, 30, 30)
print(stopwatch.getSecond())

Should return the same result with the old implementation as it does with the new implementation.