This Python program defines a class named Time that stores hour, minute, and second values.
It includes a method called isEqual() that compares two Time objects and checks whether they represent the same time.
# Define the Time class
class Time:
def __init__(self, hour, minute, second):
self.hour = hour
self.minute = minute
self.second = second
def isEqual(self, other):
return (self.hour == other.hour and
self.minute == other.minute and
self.second == other.second)
# Create two Time objects
t1 = Time(14, 30, 15)
t2 = Time(14, 30, 15)
# Compare the two times
if t1.isEqual(t2):
print("Times are equal")
else:
print("Times are different")
Times are equal
- The Time class has three fields: hour, minute, and second
- The isEqual() method compares each field of two Time objects
- If all three fields match, the method returns True
- The result is printed based on the comparison outcome