为了账号安全,请及时绑定邮箱和手机立即绑定

下面的代码为什么一直显示错误?

class Company(object):

num = 0

name = []

def __init__(self,Company_name,Desc,Profit,TotalSales,TotalCost,EmployeeName):

    self.Company_name = Company_name

    self.Desc = Desc

    self.Profit = Profit

    self.TotalSales = TotalSales

    self.TotalCost = TotalCost

    self.EmployeeName = EmployeeName

    self.Employee_number = len(self.EmployeeName)

    self.class.num += 1#为什么这里一直显示错误?

    self.class.name.append(Company_name)

def recuitment(self,r_name,r_salary):

    self.EmployeeName.append(r_name)

    self.TotalCost += r_salary

    self.Employee_number += 1

def fire(self,f_name,f_salary):

    self.EmployeeName.remove(f_name)

    self.TotalCost -=f_salary

    self.Employee_number -= 1

def advertise(self,ad_cost):

    self.TotalCost += ad_cost

def s_security(self,s_cost):

    self.TotalCost += s_cost*self.Employee_number

def tax(self,t_cost):

    self.TotalCost += t_cost*self.Employee_number

def sale(self,sale_number,price,Profit_rate,):

    self.Totalsales += sale_number*price

    self.Profit+= sale_number*Profit_rate

def get_employee(self):

    return self.EmployeeName

def get_profit(self):

    return self.Profit

@classmethod

def get_num(cls):

    return cls.num

@classmethod

def get_name(cls):

    return cls.name


正在回答

1 回答

Company.num += 1  # 应该num和name是局部变量,如果想改的话,使用类属性去改,即Company.num,name同理。
Company.name.append(Company_name)
0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
python进阶
  • 参与学习       255665    人
  • 解答问题       2949    个

学习函数式、模块和面向对象编程,掌握Python高级程序设计

进入课程

下面的代码为什么一直显示错误?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信