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

相关推荐

大专境巅峰电子狗:头一次看到这种简历,学术与技术学习,直接用技能概括就好了呀,实习经历要写丰富一点
点赞 评论 收藏
分享
牛客96763241...:杭电✌️也是打完招呼,没人回吗
点赞 评论 收藏
分享
评论
5
收藏
分享

创作者周榜

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