This is my code:

class MyTime:

    def __init__(self, hrs=0, mins=0, secs=0):
        self.hours = hrs
        self.minutes = mins
        self.seconds = secs

        if self.seconds >= 60:
            self.minutes += self.seconds // 60
            self.seconds = self.seconds % 60

        if self.minutes >= 60:
            self.hours += self.minutes // 60
            self.minutes = self.minutes % 60

        if self.hours >= 24:
            self.hours = self.hours % 24

    def get_sec(self):
        return (self.hours * 60 + self.minutes) * 60 + self.seconds

    def __str__(self):
        return "{:02d}:{:02d}:{:02d}".\
               format(self.hours, self.minutes, self.seconds)

    def between(self, t1, t2):
        return (t1.get_sec()) <= (self.get_sec()) and (self.get_sec()) <= (t2.get_sec())



t1 = (9, 59, 59)
print("t1 =", t1)

t2 = (10, 0, 1)
print("t2 =", t2)

t3 = (10, 0, 0)
print("t3 =", t3)

print (t2.between(t1, t3))

I keep getting an error: AttributeError: 'tuple' object has no attribute 'between'

The traceback says: Traceback (most recent call last):
  File "<string>", line 420, in run_nodebug
  File "C:\Users\Desktop\module1.py", line 40, in <module>
    print t2.between(t1, t3)
AttributeError: 'tuple' object has no attribute 'between'

Any help would be great, thank you!

As the error message says, tuples don't have a between method, so you can't do t.between(...) where t is a tuple.

You can call between on MyTime objects because you defined a between method for the MyTime class. So if you create an object of that class (by using MyTime(...)), you can call between on that object.

So how would i go about being able to use thebetween method? I can't seem to get it to work at all

As sepp2k said, create MyTime instances t1 = MyTime(9, 59, 59), etc.

And now I get this error after doing that:

Traceback (most recent call last):
  File "<string>", line 420, in run_nodebug
  File "C:\Users\Desktop\module1.py", line 40, in <module>
    final = MyTime(t1, t2, t3)
  File "C:\Users\Desktop\module1.py", line 10, in __init__
    if self.seconds >= 60:
TypeError: unorderable types: MyTime() >= int()
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.