如何解决关于对象的 Python 属性错误
嘿,我正在努力提高 Python 方面的能力并决定去上课。我运行代码,它一直运行到它调用对象Employees。它给了我一个属性错误:类型对象“员工”没有属性“HourlyAssociate”。谁能帮我吗。我四处寻找修复方法并尝试了一些方法,但我遇到了障碍。
class Employees:
def __init__(self,name):
self.name = name
def setName(self,name):
self.name = name
def getName(self):
return self.name
class SalariedEmployee(Employees):
def __init__(self,name,rate,monthly):
rate.monthly = monthly
Employees.__init__(self,name)
def setMonthly(rate,monthly):
rate.monthly = monthly
def getMonthly(rate,monthly):
return rate.monthly
class HourlyEmployee(Employees):
def __init__(self,hourly,time,hours):
rate.hourly= hourly
Employees.__init__(self,name)
def setHourly(rate,hourly):
rate.hourly = hourly
def getHourly(rate):
return rate.hourly
def setHours(time,hours):
time.hours = hours
def getHours(time,hours):
time.hours = hours
import Employee
#main function
def main():
associates=AssociateList()
print('All associates hired for the company: ')
display_associates(associates)
#function for user input,and storing in the objects created. Then store in the array
def AssociateList():
#an empty array for employee data
associate_list = []
# Input to get the number of employee's date the user will be entering in
numOfAssociates = int(input('How many workers hired today? '))
#loop for input for each employee
for num in range(numOfAssociates):
#input data
name = input('Enter the name of the worker: ')
answer = str(input('Enter if associate is hourly or salary: '))
if answer == ('hourly'):
hours = int(input('Enter the amount of hours: '))
hourly = float(input('Enter the hourly rate: '))
else:
monthlyRate = int(input('Enter the monthly rate: '))
print()
associates = Employees.HourlyAssociate(name,hours,hourly)
associates = Employees.SalaryAssociate(name,monthlyRate)
associate_list.append(associate)
return associate_list
def display_associate(associate_list):
for associate in associate_list:
print('Name:',associate.get_name())
print('Hourly rate: $',associate.get_Hourlyrate())
print('Hours worked: ',associate.get_Hours())
print()
#calls the main function
main()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。