class Human:
def __init__(self, name, lastname, age):
# Исправлено имя атрибута на lastname согласно требованию теста
self.name = name
self.lastname = lastname
self.age = age
def __str__(self):
# Формат: Имя Фамилия (перенос строки) Возраст: значение
return f"{self.name} {self.lastname}\nВозраст: {self.age}"
def __gt__(self, other):
if isinstance(other, Human):
return self.age > other.age
return NotImplemented
def __ge__(self, other):
if isinstance(other, Human):
return self.age >= other.age
return NotImplemented
def __lt__(self, other):
if isinstance(other, Human):
return self.age < other.age
return NotImplemented
def __le__(self, other):
if isinstance(other, Human):
return self.age <= other.age
return NotImplemented
def __eq__(self, other):
if isinstance(other, Human):
return self.age == other.age
return NotImplemented
# Проверка
h1 = Human("Иван", "Доберман", 30)
h2 = Human("Степан", "Крикун", 25)
print(h1)
print(h2)
if h1 > h2:
print(f"{h1.name} старше, чем {h2.name}")