题解 | #修改属性2#

修改属性2

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

class Employee:

    def __init__(self,name,salary):
        self.name = name
        self.salary = salary

    def setattr(self):
        self.age = int(input())

    def hasattr(self):
        try:
            self.age
        except:
            print(False)
            self.setattr()
        else:
            print(True)


    def printclass(self):
        return f"{self.name}'salary is {self.salary}, and his age is {self.age}"


a = input()
b = int(input())
e = Employee(a,b)
e.hasattr()
print(e.printclass())

全部评论

相关推荐

无情咸鱼王的秋招日记之薛定谔的Offer:好拒信,偷了,希望有机会用到
点赞 评论 收藏
分享
4 收藏 评论
分享
牛客网
牛客企业服务