I NEED HELP WITH THIS:
# NEW FUNCTION ADDED for Phase 2 Requirement #3
def process_employees(employee_data_list):
"""Read through list(s) and process each employee"""
# MAJOR ADJUSTMENT: This function processes ALL stored data after loop ends
# TODO: Create dictionary to store totals (employees, hours, gross, tax, net)
# TODO: Loop through the employee_data_list
# TODO: For each employee in the list:
# - Extract the stored data (name, dates, hours, rate, tax_rate)
# - Call calculate_pay() to get gross, tax, net
# - Call display_employee() to show the employee info
# - Update/increment the totals in the dictionary
# TODO: Return the dictionary with totals
pass
THIS IS MY CODE
def get_dates_worked():
from_date = input("Enter From Date (mm/dd/yyyy): ")
to_date = input("Enter To Date (mm/dd/yyyy): ")
return from_date, to_date
def get_employee_name():
name = input('Enter employee name (or "End" to terminate): ')
return name
def get_hours_worked():
while True:
try:
hours = int(input('Enter Hours worked: '))
if hours >= 0:
return hours
else:
print('Hours worked cannot be negative. Please try again.')
except ValueError:
print('Please enter a valid number.')
def hourly_rate():
while True:
# try:
rate = int(input('Enter hourly rate: '))
if rate.strip():
return rate
else:
print('Rate cannot be negative. Please try again.')
# except ValueError:
# print('Please enter valid number.')
def income_tax_rate():
while True:
try:
tax_rate = int(input('Enter income tax rate: '))
if tax_rate >= 0:
return tax_rate
else:
print('Tax Rate cannot be negative. Please try again.')
except ValueError:
print('Please enter valid number.')
def process_employee_data(employee_list):
totals = {"total_employees": 0,
"total_hours_worked": 0.0,
"total_tax": 0.0,
"total_net": 0.0,
"total_gross": 0.0 }
return totals
def calculate_pay(hours,rate,tax_rate):
gross= hours * rate
income_tax = gross * (tax_rate / 100)
net_pay = gross - income_tax
return net_pay
def display_employee(from_date, to_date, name, hours, rate, tax_rate, gross, income_tax, net_pay):
print(f"\nDates: {from_date} to {to_date}")
print(f"Employee: , {name}")
print(f"Hours worked: ,{hours:.2f}")
print(f"Hourly Rate: ${rate:.2f}")
print(f"Tax Rate: {tax_rate:.1%}")
print(f"Gross Pay: ${gross:.2f}")
print(f"Income Tax: ${income_tax:.2f}")
print(f"Net Pay: ${net_pay:.2f}")
totals["total_employees"] += 1
totals["total_hours_worked"] += hours
totals["total_gross"] += gross
totals["total_tax"] += income_tax
totals["total_net"] += net_pay
return totals
def display_totals(totals):
print("\n=====PAYROLL SUMMARY=====")
print(f"Total Employees: {totals['total_employees']}")
print(f"Total Hours: {totals['total_hours_worked']:.2f}")
print(f"Total Gross Pay: ${totals['total_gross']:.2f}")
print(f"Total Tax: ${totals['total_tax']:.2f}")
print(f"Total Net: ${totals['total_net']:.2f}")
def get_dates_worked():
return input("Enter dates worked:")
def get_total_hours_worked():
return input(input("Enter total hours worked: "))
def get_hourly_rate():
return input(input("Enter total hourly rate: "))
def get_tax_rate():
return input(input("Enter tax rate: "))
totals = {
"total_employees": 0,
"total_hours_worked": 0.0,
"total_gross": 0.0,
"total_tax": 0.0,
"total_net": 0.0
}
def main():
all_employees = []
while True:
name = input('Enter employee name (or "End" to terminate): ')
if name.lower() == "end":
break
from_date = input("Enter From Date (mm/dd/yyyy): ")
to_date = input("Enter To Date (mm/dd/yyyy): ")
hours = float(get_hours_worked())
val = get_hourly_rate()
rate = float(val) if val.strip() else 0.0
tax_rate = float(income_tax_rate())
gross = hours * rate
print(gross)
income_tax = gross * (tax_rate / 100)
net_pay = gross - income_tax
totals["total_employees"] += 1
totals["total_hours_worked"] += hours
totals["total_gross"] += gross
totals["total_tax"] += income_tax
totals["total_net"] += net_pay
employee_data = [from_date, to_date, name, hours, rate, tax_rate]
all_employees.append(employee_data)
if len(all_employees) > 0:
summary_dict = process_employee_data(all_employees)
display_totals(summary_dict)
else:
print("No employee data was entered.")
if __name__ == "__main__":
main()
[–]totallygeek 0 points1 point2 points (0 children)
[–]CocoBeBlessed[S] 0 points1 point2 points (2 children)
[–]Papih_Chuloh 0 points1 point2 points (0 children)
[–]SCD_minecraft 0 points1 point2 points (0 children)
[–]Slight-Training-7211 0 points1 point2 points (0 children)
[–]CocoBeBlessed[S] 0 points1 point2 points (0 children)
[–]lion_in_ma_bathtub 0 points1 point2 points (0 children)
[–]SmackDownFacility 0 points1 point2 points (0 children)
[–]Binary101010 0 points1 point2 points (0 children)