题解 | #修改属性1#

修改属性1

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

定义接收数据的变量

name = input()
salary = int(input())
age = int(input())

定义Employee类与相关函数

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

    def printclass(self):
        print("%s'salary is %s, and his age is %s" % (self.name, self.salary, self.age))

实例化Employee类并做判断

e = Employee(name, salary)
try:
    e.printclass()
except:
    print("Error! No age")
    e.age = age
    e.printclass()
全部评论

相关推荐

Rena1ssanc...:对的,要是面评没太烂,勤更新简历等捞就行了,腾讯可以无限复活
点赞 评论 收藏
分享
吴offer选手:HR:我KPI到手了就行,合不合适关我什么事
点赞 评论 收藏
分享
评论
5
收藏
分享

创作者周榜

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