# Arup Guha
# 6/5/2026
# Running Example
# This creates a Runner object that has as part of it Time objects.

class Time:

    # The constructor for the time object
    def __init__(self, m, s):
        self.minutes = m + s//60
        self.seconds = s % 60

    # Returns the number of minutes a Time object is.
    def totalSeconds(self):
        return 60 * self.minutes + self.seconds

    # Will help with sorting.
    def __lt__(self, other):
        return self.totalSeconds() < other.totalSeconds()

    # Adds the Time of the argument with the object the method is called on
    # together and returns their sum as a Time object.
    def addTime(self, time2):
        mins = self.totalSeconds() + time2.totalSeconds()
        return Time(mins)

    # Returns the difference in Time between the argument and the object
    # the method is called on. A Time object is returned.
    def difference(self, time2):
        mins = abs(self.totalSeconds() - time2.totalSeconds())
        return Time(mins)

    # String representation of the object.
    def __str__(self):
        return str(int(self.minutes)) + ":" + str(int(self.seconds))

class Runner:

    # A runner starts with no events.
    def __init__(self, fName, lName):
        self.firstName = fName
        self.lastName = lName
        self.runTimes = {}

    # Add the event with name eventName with time eventTime to this runner.
    def addEvent(self, eventName, eventTime):

        # No previous time recorded, add it.
        if not eventName in self.runTimes:
            self.runTimes[eventName] = eventTime

        # Otherwise, only add if this time is strictly better.
        elif eventTime < self.runTimes[eventName]:
            self.runTimes[eventName] = eventTime

    # Returns a string representation of the runner.
    def __str__(self):

        # Header
        retval = "Runner: "+self.firstName+" "+self.lastName+"\n"

        # Add all races.
        for race in self.runTimes:
            retval = retval + "Event: "+race+" Time = "+str(self.runTimes[race])+"\n"

        # Ta da!
        return retval

# To test the runner.
def main():

    # Make an object and print it.
    fastGuy = Runner("Noah", "Lyles")
    print(fastGuy)

    # Do one event.
    fastGuy.addEvent("100 meter dash", Time(0, 10) )
    print(fastGuy)

    # Add two more.
    fastGuy.addEvent("200 meter dash", Time(0, 21) )
    fastGuy.addEvent("1 mile run", Time(4, 30) )
    print(fastGuy)

    # Now let's add duplicates.
    fastGuy.addEvent("100 meter dash", Time(0, 11) )
    fastGuy.addEvent("200 meter dash", Time(0, 19) )
    print(fastGuy)

# Run it, pun intended!
main()
