Write a PYTHON program that displays a weekly payroll report. A loop in the program should ask the user for the employee number, gross pay, state tax, federal tax, and FICA withholdings. The loop will terminate when 0 is entered for the employee number. After the data is entered, the program should display totals for gross pay, state tax, federal tax, FICA withholdings, and net pay. Input Validation: ▪ Do not accept negative numbers for any of the items entered. ▪ Do not accept values for state, federal, or FICA withholdings that are greater than the gross pay. ▪ If the sum of state tax + federal tax + FICA withholdings for any employee is greater than gross pay, print an error message and ask the user to reenter the data for that employee.
ANSWER:
emp_num, gross_pay, state_tax, federal_tax, fica_withholding, net=[],[],[],[],[],[]
total_chk = False
while True:
if(not total_chk):
emp = int(input("Enter employee number: "))
if emp!=0:
while True:
g_pay = int(input("Enter gross pay: "))
if g_pay<0:
print("Gross Pay can not be negative. Please try again !")
g_pay = int(input("Enter gross pay: "))
else:
break
else:
if(len(emp_num)):
print("Gross Pay","State Tax", "Federal Tax", "FICA Withholdings", "Net Pay" ,sep=" * ")
print(sum(gross_pay),sum(state_tax),sum(federal_tax),sum(fica_withholding),sum(net), sep=" * ")
else:
print("No data entered")
break
state = int(input("Enter state tax: "))
while True:
if state<0:
print("State tax can not be negative. Please try again !")
state = int(input("Enter state tax: "))
elif state>g_pay:
print("State tax can not be more than gross pay. Please try again !")
state = int(input("Enter state tax: "))
else:
break
federal = int(input("Enter federal tax: "))
while True:
if federal<0:
print("federal tax can not be negative. Please try again !")
federal = int(input("Enter federal tax: "))
elif federal>g_pay:
print("federal tax can not be more than gross pay. Please try again !")
federal = int(input("Enter federal tax: "))
else:
break
fica = int(input("Enter FICA withholdings: "))
while True:
if fica<0:
print("FICA withholdings can not be negative. Please try again !")
fica = int(input("Enter FICA withholdings: "))
elif fica>g_pay:
print("FICA withholdings can not be more than gross pay. Please try again !")
fica = int(input("Enter FICA withholdings: "))
else:
break
if(state+federal+fica > g_pay):
print("Error: sum of federal tax, state tax and Fica withholdings can't be more than gross pay")
print("Please reenter data for employee with employee number =",emp)
total_chk=True
else:
total_chk=False
emp_num.append(emp)
gross_pay.append(g_pay)
state_tax.append(state)
federal_tax.append(federal)
fica_withholding.append(fica)
net.append(g_pay-state-federal-fica)
NOTE: The above code is in Python3. Please refer to the attached screenshots for code indentation and sample I/O.
SAMPLE I/O:
1.
2.
Get Answers For Free
Most questions answered within 1 hours.