Files
python-test/test9.py
T

25 lines
651 B
Python
Raw Normal View History

2023-03-31 12:03:53 -07:00
class Temperature:
temperature: float
def __init__(self, temperature):
self.temperature = temperature
def __add__(self, operand):
if operand.__class__ != '__main__.Temperature':
raise ValueError(f"That's not a temperature object! It's a {operand.__class__}!")
self.temperature += operand.temperature
def __str__(self):
return f"{self.temperature=}"
def insert_object(self, obj):
self.temperature += obj.temperature
if __name__ == "__main__":
oven = Temperature(180.0)
chicken = Temperature(5.0)
print(f"{chicken + oven=}")
oven.insert_object(chicken)