Hello everyone, I have stumbled across this wonderful site while trying to find assistance with Python. Being virtual in my class is making this very difficult for me. The problem I am working on has three parts to it.
PART 1
Build a payroll solution prompting for employee name, hours worked, and pay rate. Calculate the gross pay as hours worked * pay rate. Calculate the taxes (straight 20%) to be deducted. Then display the employee name, hours worked, gross pay taxes, and net pay you calculated.
Here is my code for Part 1
#Prompt the user to enter their name.
name = input("What Is Your Name?")
#Prompt the user to enter their hours worked.
hours = float(input("How Many Hours Did You Work This Week?"))
#Prompt the user to enter their hourly pay rate.
rate = float(input("What Is Your Current Hourly Pay Rate?"))
#Prompt the user to enter the federal tax withholding rate.
federal_tax_rate = float(input("What Is Your Current Federal Tax Withholding Rate?"))
#Display user name.
print ("Employee Name:",name)
#Display users working hours.
print ("Hours Worked:",hours)
#Display users rate of pay.
print ("Pay Rate:$",rate)
#Display users Gross Pay.
print ("Gross Pay:$",rate * hours)
#Display users deductions.
print ("Deductions:")
#Calculate and print the Federal tax withholding.
print (" Federal Withholding (",federal_tax_rate*100,"%): ${:.2f}".format(rate * hours * federal_tax_rate,'.2f'))
#Calculate and print the total deduction.
print (" Total Deduction: ${:.2f}".format(rate * hours * federal_tax_rate))
#Calculate and print the net pay.
print ("Net Pay: $ {:.2f}".format(rate * hours - rate * hours * federal_tax_rate))
PART 2
Modify the program from PART 1 in two ways:
- Embedding the code in a loop, so multiple employees can be calculated without restarting the program. Terminate the loop when no employee name is entered.
- modify the tax calculation so that anyone
- making less than $385 pays $0 tax,
- makes < $576 pays 15% tax,
- makes less than $769 pays 20% tax
- and all others pay 25% tax.
Here is my code for Part 2 where I am stuck. I think I am actually combining part three in this as well. I am just so confused currently.
while True:
# Prompt the user to enter their name.
name = input("What Is Your Name? ")
if name == "": # if name is blank exit the loop
break
# Prompt the user to enter their hours worked.
hours = float(input("How Many Hours Did You Work This Week? "))
# Prompt the user to enter their hourly pay rate.
rate = float(input("What Is Your Current Hourly Pay Rate? "))
# Display user name.
print("Employee Name:", name)
# Display users working hours.
print("Hours Worked:", hours)
# Display users rate of pay.
print("Pay Rate:$", rate)
grossPay = rate * hours
# Display users Gross Pay.
if grossPay < 385: # less than 385 0 tax
return 0;
elif grossPay >= 385 or grossPay < 576: # less than 576 15% tax
return (grossPay * 15) / 100 # 15% tax
elif grossPay >= 576 or grossPay < 769: # less than 769 20% tax
return (grossPay * 20) / 100 # 20% tax
else: # all other 25% tax
return (grossPay * 25) / 100 # 25% tax
# print("Gross Pay:$", grossPay)
print("Gross Pay:$", rate * hours)
# Calculate and print the total deduction.
print(" Total Deduction: ${:.2f}".format(federal_tax_withholding + tax))
# Calculate and print the net pay.
print("Net Pay: $ {:.2f}".format(netPay))
print()
PART 3
Modify the program from PART 2 moving the tax calculation into a function to be called TaxCalc.