哦,天哪。我已经成为这里的常客了。我有我所有的代码,但是很奇怪,因为我已经尽了最大的努力,但是我似乎不能让它工作。我试过重写它的一部分,甚至做一些小的修改,但是它就是不工作。完全不工作。
"""
WeeklyPay.py helps calculate the gross pay of multiple employees based on the hours they worked and their hourly rate
"""
def main():
"""
call other modules to get the work done
:return: None
"""
total_gross_pay = 0
total_hours_worked = 0
employee_quantity = 0
company_employee = input("Did the employee work this week? Y or y for yes: ")
while company_employee == "y" or "Y":
employee_quantity += 1
name, hours, rate = get_info()
gross_pay = caculate_gross_pay(hours, rate)
pay_stub(name, hours, rate, gross_pay)
total_gross_pay += gross_pay
total_hours_worked += hours
company_employee = input("Have more employees worked? Y or y for yes: ")
show_summary(employee_quantity, total_hours_worked, total_gross_pay)
def get_info():
"""
This module gets the needed info from employees
:return: name, hours_worked, pay_rate
"""
name = input("Enter the employee's name: ")
hours_worked = float(input("How many hours did the employee work? "))
pay_rate = float(input("What is the employee's hourly pay rate? "))
return name, hours_worked, pay_rate
def caculate_gross_pay(hours_worked, pay_rate):
"""
Hours above 40 will be paid time and a half (1.5)
:param hours_worked:
:param pay_rate:
:return: gross_pay
"""
if hours_worked > 40:
gross_pay = 40 * pay_rate + (hours_worked - 40) * 1.5 * pay_rate
else:
gross_pay = pay_rate * hours_worked
return gross_pay
def pay_stub(name, hours_worked, pay_rate, gross_pay):
"""
This module prints the pay_stub
:param name:
:param hours_worked:
:param pay_rate:
:param gross_pay:
"""
print("Employee Name: " + name)
print("Hours Worked: %.2f"%hours_worked)
print("Hourly Pay Rate: $%.2f"%pay_rate)
print("Gross Pay: $%.2f"%gross_pay)
def show_summary(employee_quantity, total_hours, total_pay):
"""
:param employee_quantity:
:param total_hours:
:param total_pay:
:return: None
"""
print("Pay Summary ")
print("Total number of employees: {}".format(employee_quantity))
print("Total hours worked by all employees {}".format(total_hours))
print("Total pay given to employees ${:,.2f}".format(total_pay))
main()
知道我做错了什么吗?我得到了这些错误:
Traceback (most recent call last):
File "C:/Users/inge scool/PycharmProjects/Week1/WeeklyPay.py", line 80, in <module>
main()
File "C:/Users/inge scool/PycharmProjects/Week1/WeeklyPay.py", line 20, in main
pay_stub(name, hours, rate, gross_pay)
File "C:/Users/inge scool/PycharmProjects/Week1/WeeklyPay.py", line 65, in pay_stub
print("Gross Pay: $%.2f"%gross_pay)
TypeError: must be real number, not NoneType
我试着在网上搜索,不断地得到关于整数的东西,但它并不完全适用于我正在做的事情。
1条答案
按热度按时间wb1gzix01#
在回溯之后,您可以看到
gross_pay
在if/else
中返回,并且只有在运行else时才返回。只需取消缩进它,它就应该工作了。