class Employee:
def __init__(self, first, last, salary):
console.warn(f"__init__('{first}', '{last}', {salary})")
self.first = first
self.last = last
try:
self.salary = float(salary)
except:
raise ValueError(f"Invalid salary: {salary}")
def __str__(self):
console.warn(f"__str__('{self.first}')")
return f"Full Name: {self.first} {self.last}, Salary: US ${self.salary:,.2f}"
def __add__(self, other):
console.warn('__add__()')
return self.salary + other.salary
def __eq__(self, other):
console.warn('__eq__()')
return self.salary == other.salary
akio = Employee('Akio', 'Kasai', 50_000.99)
print(akio)
taro = Employee('Taro', 'Yamada', 80_000.99)
print(taro)
total_salary = akio + taro
print(f"Total salary: US ${total_salary:,.2f}")
print('akio.salary == taro.salary' if akio == taro else 'akio.salary != taro.salary')