题解 | #修改属性1#

修改属性1

https://www.nowcoder.com/practice/c5ab441e5e8f4ec7bf36ba51a3141340

class Employee():
    def __init__(self, name, salary) -> None:
        self.name = name
        self.salary = salary
    def printclass(self):
        try:
            print(f"""{self.name}'salary is {self.salary}, and his age is {self.age}""")
        except AttributeError:
            print('Error! No age')
name_ = input()
salary_ = int(input())
age_ = int(input())

e = Employee(name_, salary_)
e.printclass()

# adding attribute dynamically 
e.age = age_
e.printclass()

全部评论

相关推荐

02-26 13:56
已编辑
重庆财经学院 Java
King987:你有实习经历,但是写的也太简单了,这肯定是不行的,你主要要包装实习经历这一块,看我的作品,你自己包装一下吧,或者发我,我给你出一期作品
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务