题解 | #修改属性2#

修改属性2

https://www.nowcoder.com/practice/7831806be5684ad6ac0f8b43e3e3558e

class Employee:
    def __init__(self, name, salary):
        self.name = name
        self.salary = int(salary)  # 将输入的字符串转换为整数

    def printclass(self):
        try:
            self.age
        except AttributeError:
            print("Error! No age")
        else:
            print("{}'salary is {}, and his age is {}".format(self.name, self.salary, self.age))

name = input()
salary = int(input())  # 将输入的字符串转换为整数
e = Employee(name, salary)

print(hasattr(e, 'age'))

e.age = int(input())  # 将输入的字符串转换为整数
e.printclass()

全部评论

相关推荐

本神尊:看来是没招到小红薯上的人
点赞 评论 收藏
分享
06-16 15:04
黑龙江大学 Java
零OFFER战士:另一个版本查看图片
点赞 评论 收藏
分享
迟缓的斜杠青年巴比Q...:简历被投过的公司卖出去了,我前两天遇到过更离谱的,打电话来问我有没有意向报班学Java学习,服了,还拿我学校一个学长在他们那报班学了之后干了华为OD当招牌
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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