I have a hmwk assignment that i'm stuck on....It calls for a while loop so I need to basically repeat this 4 times but I cannot for the life of me figure it out....any help would be great I narrow the code down so it works when I input the hours and rates...I just need to repeat this

Make a flowchart and write the Python 3.0 program for the following problem. A list of employees names, hours worked in a week and the hourly rate of pay is entered. Read in each employee’s data and print out the pay for the week ( including 1.5 times overtime pay for hours over 40). At the end, print the total pay for all employees. Some sample data is shown below (with the corresponding output). Hint: First write a while loop to read in employee data (one employee at a time) and print it. Then enhance your work to process an employee without overtime pay. Then include overtime pay and finally, produce the total pay.

Run#1:

Input:

“John Smith”, 50, 10

“Jane Doe”, 40, 15

“Mark Manning”, 60, 12

“ “, 0, 0

Output:

John Smith’s pay=$550.00

Jane Doe’s pay=$600.00

Mark Manning’s pay=$840.00

Total pay=$1990.00

#This program calculates and prints pay given
#rate and hours worked


employeeName=str(input("Enter employee name: "))

rate=float(input("Enter rate: "))
hours=float(input("Enter hours worked: "))

if hours>40:
    pay = 40 * rate + (hours - 40) * 1.5 * rate
    if hours>40:
        overtime=(hours - 40) * 1.5 * rate
        print("For this week overtime earned $",overtime)
else:
    pay = hours * rate
    overtime=(hours - 40) * 1.5 * rate
    print("For this week overtime earned $",overtime)
print("For this week you earned $",pay

Edited 7 Years Ago by vegaseat: added code tags

hi,
here's what you can do:

for i in range( 4 ):  # since you want 4 repetitions
    employeeName = str( input( "Enter employee name: " ) )

    rate = float( input( "Enter rate: " ) )
    hours = float( input( "Enter hours worked: " ) )

    if hours>40:
        pay = 40 * rate + ( hours - 40 ) * 1.5 * rate
        overtime = ( hours - 40 ) * 1.5 * rate
        print ( "For this week overtime earned $", overtime )
    else:
        pay = hours * rate
        overtime = ( hours - 40 ) * 1.5 * rate
        print ( "For this week overtime earned $",overtime )
    print ( "For this week you earned $", pay )
    print

just put everything in a for loop :)
pls next time put code tags, it's hard to read otherwise

hope this helps :)

Comments
very helpful information

@ soldner :)
yes range starts from 0 by default, so range( 4 ) returns [ 0, 1, 2, 3 ], excluding the index as required here:

It calls for a while loop so I need to basically repeat this 4 times

range( 3 ) would produce [ 0, 1, 2 ] :)

This question has already been answered. Start a new discussion instead.