class Employee: def __init__(self, name, salary): self.name = name self.salary = salary def printclass(self): try: self.age except AttributeError: print("Error! No age") else: print(f"{self.name}'salary is {self.salary}, and his age is {self.age}") # 创建 Employee 实例 e e = Employee(input(), int(input())) # 调用 printclass 方法输出信息 e.printclass() # 根据输入的年龄为实例 e 添加属性 age,并再次调用 printclass 方法输出信息 age = int(input()) e.age = age e.printclass()