'TypeError: must be real number, not none type plus more errors

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?



Solution 1:[1]

   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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 deepAgrawal