Ответ:
class Log:
# init
def __init__(self, length, diameter):
self.length = length
self.diameter = diameter
# equal
def __eq__(self, other):
return self.length * self.diameter == other.length * other.diameter
# not equal
def __ne__(self, other):
return self.length * self.diameter != other.length * other.diameter
# less
def __lt__(self, other):
return self.length * self.diameter < other.length * other.diameter
# less equal
def __le__(self, other):
return self.length * self.diameter <= other.length * other.diameter
# great
def __gt__(self, other):
return self.length * self.diameter > other.length * other.diameter
# great equal
def __ge__(self, other):
return self.length * self.diameter >= other.length * other.diameter
def print_volume(self):
return self.length * self.diameter
if __name__ == "__main__":
log1 = Log(10, 10)
log2 = Log(10, 10)
log3 = Log(20, 10) # examples
print(f"Бревно 1 ({log1.print_volume()}) {'' if log1==log2 else 'не '}равно бревну 2 ({log2.print_volume()})")
print(f"Бревно 1 ({log1.print_volume()}) {'' if log1 == log3 else 'не '}равно бревну 3 ({log3.print_volume()})")
print(f"Бревно 1 ({log1.print_volume()}) {'больше' if log1 > log3 else 'меньше'} бревну 3 ({log3.print_volume()})")
print(f"Бревно 1 ({log1.print_volume()}) {'меньше' if log1 < log3 else 'больше'} бревну 3 ({log3.print_volume()})")
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
Ответ:
class Log:
# init
def __init__(self, length, diameter):
self.length = length
self.diameter = diameter
# equal
def __eq__(self, other):
return self.length * self.diameter == other.length * other.diameter
# not equal
def __ne__(self, other):
return self.length * self.diameter != other.length * other.diameter
# less
def __lt__(self, other):
return self.length * self.diameter < other.length * other.diameter
# less equal
def __le__(self, other):
return self.length * self.diameter <= other.length * other.diameter
# great
def __gt__(self, other):
return self.length * self.diameter > other.length * other.diameter
# great equal
def __ge__(self, other):
return self.length * self.diameter >= other.length * other.diameter
def print_volume(self):
return self.length * self.diameter
if __name__ == "__main__":
log1 = Log(10, 10)
log2 = Log(10, 10)
log3 = Log(20, 10)
# examples
print(f"Бревно 1 ({log1.print_volume()}) {'' if log1==log2 else 'не '}равно бревну 2 ({log2.print_volume()})")
print(f"Бревно 1 ({log1.print_volume()}) {'' if log1 == log3 else 'не '}равно бревну 3 ({log3.print_volume()})")
print(f"Бревно 1 ({log1.print_volume()}) {'больше' if log1 > log3 else 'меньше'} бревну 3 ({log3.print_volume()})")
print(f"Бревно 1 ({log1.print_volume()}) {'меньше' if log1 < log3 else 'больше'} бревну 3 ({log3.print_volume()})")