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

相关推荐

讯飞老萌新:站住!有人25还没有找到工作的吗
点赞 评论 收藏
分享
一天代码十万三:这都不能算简历吧
点赞 评论 收藏
分享
评论
4
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务