def main(): #Constants otHours = 40 otRate = 1.5 #Perform a pretest loop to take input, calculate the outputs, display the keepGoing = 'y' while keepGoing == 'y': deductions = 0 #Prompt for ID number, Hourly Rate and Hours for each employee empIDNum = int(input('Enter the employee\'s ID number: ')) hourlyRate = float(input('Hourly pay rate: ')) hoursWorked = float(input('Number of hours worked : ')) #Calculate regular and overtime pay if hoursWorked <= 40: regHours = hoursWorked regPay = regHours * hourlyRate otHours = 0 otPay = 0 else: regHours = 40 regPay = regHours * hourlyRate otHours = hoursWorked - 40 otPay = otHours * hourlyRate * 1.5 #Gross pay is regular and overtime pay combined weeklyGrossPay = regPay + otPay #Calculate net pay #For Gross incomes > $500, deduct 15% of gross for tax #All employees pay $20 parking fee if weeklyGrossPay > 500: deductions = weeklyGrossPay * .15 netPay = weeklyGrossPay - deductions - 20 else: netPay = weeklyGrossPay -20 #Display print('ID Number: ', empIDNum) print('Pay Rate: $', format(hourlyRate, ',.2f'), sep='') print('Regular Hours: ', regHours) print('Overtime Hours: ', format(otHours, ',.2f'), sep='') print('Total Hours: ', hoursWorked) print('Regular Pay: $', format(regPay, '.2f'), sep='') print('Overtime Pay: $', format(otPay, ',.2f'), sep='') print('Gross Pay: $', weeklyGrossPay) print('Deductions: $', format(deductions, ',.2f'), sep='') print('Net Pay: $', format(netPay, ',.2f'), sep='') #Prompt user if they would like to process another employee keepGoing = input('Calculate another? (Enter y for yes): ') # End of main # Call functions main()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question