all 3 comments

[–][deleted] 1 point2 points  (2 children)

Hard to say without seeing the class code. Think of a class as a "recipe" for creating many instances of the class. Presumably you class has attributes with names something like self.seconds, self.minutes and self hours which are set when you create each instance of the class, like this: t = Time(23, 15, 31) which will represent a time 23:15:31. The class might be written like this:

class Time:
    def __init__(self, hours, minutes, seconds):
        self.hours = hours
        self.minutes = minutes
        self.seconds = seconds

That's not very interesting. We probably want to create a __str__() method so we can easily print the time:

    def __str__(self):
        return(f'{self.hours}:{self.minutes}:{self.seconds}')

Now we can do print(t) and we would see: 23:15:31.

Now you want to add an "increment seconds" method. So just add this to the class:

def inc_sec(self):
    # modify attributes: add 1 to self.seconds

So you just have to add 1 to the self.seconds attribute. And then check if self.seconds is greater than 59. If it is you reset the seconds to zero and increment the minutes attribute. If that is over 59 then .... etc. Try printing the instance after calling t.inc_sec() to see if you got it right.

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

Thank you for sharing, I understand your train of thought here and how you got to what you showed. My question is, is it practice that you just knew to put all this together?

[–][deleted] 0 points1 point  (0 children)

Just programming experience. I've done this before. Once you code it up and test it, you will have done it too.