Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python: Program is only multiplying the last number the user inputs rather than all of them

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 = ' ')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading