[英]What do we need to do to fix this equation so that it works in our Python code?
Assignment and code below...下面的分配和代码...
I am assisting my son with his homework.我正在帮助我儿子做作业。 I know coding, but not Python.
我知道编码,但不知道 Python。 He has gotten this far and has asked me to jump in to assist and I am stumped.
他已经走到了这一步,并要求我加入协助,我被难住了。 I believe that the equation for the total take-home salary is too long, but I am not sure what to do to help.
我认为实得工资总额的公式太长,但我不知道该怎么做才能提供帮助。 The code works as is, but when we try to switch the
"...will take home $" + str(emp_1.salary) + ", after taxes." with "...will take home $" + str(emp_1.apply_taxes()) + ", after taxes."
代码按原样工作,但是当我们尝试切换
"...will take home $" + str(emp_1.salary) + ", after taxes." with "...will take home $" + str(emp_1.apply_taxes()) + ", after taxes."
"...will take home $" + str(emp_1.salary) + ", after taxes." with "...will take home $" + str(emp_1.apply_taxes()) + ", after taxes."
for both emp_1
and emp_2
we get an error that apply_taxes
is not defined.对于
emp_1
和emp_2
,我们得到一个错误,即apply_taxes
。 all we need to do is get the equation to work and we will be good.我们需要做的就是让方程式起作用,我们会做得很好。 Any suggestions would be greatly appreciated!
任何建议将不胜感激!
Thank you!!谢谢!!
This is the assignment:这是作业:
This is the code that we have:这是我们拥有的代码:
class Employee:
fed_tax = float(.2)
state_tax = float(.0314)
def __init__(self, name, salary):
self.name = name
self.salary = salary
def apply_taxes(self):
self.salary = int(float(self.salary - ((self.salary * float(self.fed_tax)) + (self.salary * float(self.state_tax)))))
emp_1 = Employee("Isaac Soiffer", 50000)
emp_2 = Employee("Jack Fuller", 45000)
print("The employee, " + emp_1.name + ", salary is $" + str(emp_1.salary) + ".")
print("Employee " + emp_1.name + " will take home $" + str(emp_1.salary) + ", after taxes.")
print("The employee, " + emp_2.name + ", salary is $" + str(emp_2.salary) + ".")
print("Employee " + emp_2.name + " will take home $" + str(emp_2.salary) + ", after taxes.")
you are not calling apply taxes anywhere: Try something like:您不会在任何地方调用应用税:尝试以下操作:
class Employee:
fed_tax = 0.2
state_tax = 0.0314
def __init__(self, name, salary):
self.name = name
self.salary = salary
self.post_taxed_salary = self.apply_taxes()
def apply_taxes(self):
return int(float(self.salary - ((self.salary * float(self.fed_tax)) + (self.salary * float(self.state_tax)))))
emp_1 = Employee("Isaac Soiffer", 50000)
emp_2 = Employee("Jack Fuller", 45000)
print('employee {} has salary of {} and after taxes {}'.format(emp_1.name, emp_1.salary, emp_1.post_taxed_salary))
Returns: employee Isaac Soiffer has salary of 50000 and after taxes 38430回报:员工 Isaac Soiffer 工资 50000 税后 38430
On a note, because saalary is an attribute, you can make post_taxed_salary a property, eg请注意,因为 saalary 是一个属性,所以您可以将 post_taxed_salary 设为属性,例如
class Employee:
fed_tax = 0.2
state_tax = 0.0314
def __init__(self, name, salary):
self.name = name
self.salary = salary
@property
def post_taxed_salary(self):
return int(float(self.salary - ((self.salary * float(self.fed_tax)) + (self.salary * float(self.state_tax)))))
Should work as well也应该工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.