(Financial application: payroll) Write a program that reads the following information and prints a payroll statement:
Employee’s name (e.g., Smith)
Number of hours worked in a week (e.g., 10)
Hourly pay rate (e.g., 9.75)
Federal tax withholding rate (e.g., 20%)
State tax withholding rate (e.g., 9%)
A sample run is shown below:
Enter employee's name: Smith
Enter number of hours worked in a week: 10
Enter hourly pay rate: 9.75
Enter federal tax withholding rate: 0.20
Enter state tax withholding rate: 0.09
Employee Name: Smith
Hours Worked: 10.0
Pay Rate: $9.75
Gross Pay: $97.5
Deductions:
Federal Withholding (20.0%): $19.5
State Withholding (9.0%): $8.77
Total Deduction: $28.27
Net Pay: $69.22
Financial application: payroll Program Code:
# Prompt the user to enter employee's name
employeeName = input("Enter employee's name: ")
# Prompt the user to enter the number of hours worked in a week
hoursWorked = float(input("Enter number of hours worked in a week: "))
# Prompt the user to enter the hourly pay rate
hourlyPayRate = float(input("Enter hourly pay rate: "))
# Prompt the user to enter the federal tax withholding rate
federalTaxRate = float(input("Enter federal tax withholding rate: "))
# Prompt the user to enter the state tax withholding rate
stateTaxRate = float(input("Enter state tax withholding rate: "))
# Calculate gross pay
grossPay = hoursWorked * hourlyPayRate
# Calculate federal withholding
federalWithholding = grossPay * federalTaxRate
# Calculate state withholding
stateWithholding = grossPay * stateTaxRate
# Calculate total deduction
totalDeduction = federalWithholding + stateWithholding
# Calculate net pay
net_pay = grossPay - totalDeduction
# Print the payroll statement
print("\n")
print("Employee Name:", employeeName)
print("Hours Worked:", hoursWorked)
print("Pay Rate: $", format(hourlyPayRate, ".2f"), sep="")
print("Gross Pay: $", format(grossPay, ".2f"), sep="")
print("Deductions:")
print("Federal Withholding (", format(federalTaxRate * 100, ".1f"), "%): $", format(federalWithholding, ".2f"), sep="")
print("State Withholding (", format(stateTaxRate * 100, ".1f"), "%): $", format(stateWithholding, ".2f"), sep="")
print("Total Deduction: $", format(totalDeduction, ".2f"), sep="")
print("Net Pay: $", format(net_pay, ".2f"), sep="")
Executed Output:
Enter employee's name: Smith
Enter number of hours worked in a week: 10
Enter hourly pay rate: 9.75
Enter federal tax withholding rate: 0.20
Enter state tax withholding rate: 0.09
Employee Name: Smith
Hours Worked: 10.0
Pay Rate: $9.75
Gross Pay: $97.50
Deductions:
Federal Withholding (20.0%): $19.50
State Withholding (9.0%): $8.78
Total Deduction: $28.27
Net Pay: $69.22