题解 | #修改属性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()

全部评论

相关推荐

不愿透露姓名的神秘牛友
05-01 13:13
ecece:这么明目张胆虚报就业率啊
点赞 评论 收藏
分享
03-16 13:56
湖南大学 C++
牛客872108596号:到现在没消息是挂了吗查看图片
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务