This is my first time posting. Please bare with me.
I have been working on this program for about a month and I cannot get it to run properly. When the user runs the program, you will be asked to input the hours worked by four employees. The program will then multiply the hours worked for each employee and print their gross pay for each of them. The problem is, it is only multiplying the last number I input and prints that as the gross pay for all four employees. I could really use some help.
If you need more information or want me to clarify anything, please let me know. All help is appreciated. Thank you!
Start:
NUM_EMPLOYEES = 4
employeehours = [ ]
for i in range (NUM_EMPLOYEES):
print('Enter the hours worked by employee ', i + 1, ':', sep = '', end = ' ')
employeehours = float(input())
pay_rate = 14
for i in range (NUM_EMPLOYEES):
gross_pay = employeehours * pay_rate
print('Gross pay for employee', i + 1, ': $', format(gross_pay , '.2f'), sep = ' ')
>Solution :
you are setting employeehours to last floating value. your code is right almost.
NUM_EMPLOYEES = 4
employeehours = [ ]
for i in range (NUM_EMPLOYEES):
print('Enter the hours worked by employee ', i + 1, ':', sep = '', end = ' ')
employeehours.append(float(input()))
pay_rate = 14
for i in range (NUM_EMPLOYEES):
gross_pay = employeehours[i] * pay_rate
print('Gross pay for employee', i + 1, ': $', format(gross_pay , '.2f'), sep = ' ')