添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Oh, goodness. I've become a regular here. I have all of my code but it's weird because I'm trying my best but I cannot seem to get it to work. I've tried rewriting parts of it and even making minor changes but it just won't work. At all.

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()

Any idea what I'm doing wrong? I get these errors:

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

I've tried searching online and keep getting stuff about integers with NoneType but is isn't fully applicable to what I'm doing. I'm adding numbers?

Try just print()ing out gross_pay in the pay_stub method and see what it spits out. That's a good way to start debugging and figure out what's going on. – Caleb Anthony Jan 21, 2020 at 21:39
   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 ## remove indent here

Following the traceback you can see that gross_pay is returned inside an if/else, and only returns if the else is run. Simply unindent it and it should work.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.