I'm trying to create a function that takes two prmtrs, num_of_employees and hrly_rate.
The list should consist of the number of worked hours and the pay of each employee. The size of the list should be the same as the number of employees. It prompts the user to enter the number of hours worked for each employee, calculates the pay, and creates a list of the number of hours and pay that adds it to the list.
If the number is less than 40, the pay is standard: Number of hours worked * Hourly Rate If the number is GREATER than 40, then the pay is the hourly rate is 1.5 for the hours over 40 hours.
The Code SHOULD Display this output: #assuming the number of employees is just 2,:
insert the number of worked hours: 60
insert the number of worked hours:20
the employee worked for 60 hours and the earned is 700.00$
the employee worked for 20 hours and the earned is 200.00$
But this is my Code:
def calculate_total_pay_cad(num_employees, hrly_rate_CAD):
rng = range(0, num_employees)
for n in rng:
num_hrs_worked = int(input(('Input the number of worked hours: ')))
if num_hrs_worked < 40:
pay = num_hrs_worked * hrly_rate_CAD
if num_hrs_worked > 40:
pay = num_hrs_worked * (hrly_rate_CAD * 1.5)
for n in rng:
print(f"the employee worked for {num_hrs_worked} and has earned {pay}")
num_employees = int(input(('enter number employees')))
hrly_rate_CAD = int(input(('enter hourly rate: ')))
calculate_total_pay_cad(num_employees,hrly_rate_CAD)
And this is my Output:
Input the number of worked hours: 50
Input the number of worked hours: 20
the employee worked for 20 and has earned 300
the employee worked for 20 and has earned 300
Summary = My code is only outputting the LAST insert on my list of inputs. How would I make it accompany the correct number of hours and pay calculation for each individual line?
Many thanks in advance.