题解 | #修改属性2#
修改属性2
https://www.nowcoder.com/practice/7831806be5684ad6ac0f8b43e3e3558e
import sys class Employee(): def __init__(self,name:str,salary:int): self.name=name self.salary=salary def printclass(self): print(f"{self.name}'salary is {self.salary}, and his age is {self.age}") a=input() b=int(input()) c=int(input()) e=Employee(a,b) try: e.printclass() except: print(hasattr(e,'age')) e.age=c e.printclass()