In: Computer Science
Python 3 Script: A company has classified its employees as follows.
Managers Hourly workers
Commission workers Pieceworkers
- who receive a fixed weekly salary
- who receive a fixed hourly wage for up to the first 40 hours they
work and
“time-and-a-half”, i.e. 1.5 times their hourly wage, for
overtime hours worked), - who receive $250 plus 5.7% of their gross
weekly sales)
- who receive a fixed amount of money per item for each of the
items they
Produce. Each pieceworker in this company works on only one type of item. Write a Python program to compute the weekly pay for each employee. You do not know the number of employees in advance.
Each type of employee has its own pay method. A Manager has a weekly salary and is entered while processing. Hourly worker’s salary is calculated by multiplying the rate-per-hour and the number-of- hours-worked. Commission worker’s salary is based on the gross weekly sales and uses the formula shown above. Pieceworker’s salary is calculated by multiplying the rate-per-piece and the number-of- pieces completed. Prompt the user to enter the appropriate facts your program needs to calculate each employee’s pay based on that employee’s category.
Screenshot of the code:
Sample Output:
Code to copy:
#Define the function getManagerPay() to display the
#weekly sales entered for the managers.
def getManagerPay(weekly_salary_for_manager):
print("\nThe weekly pay for the managers "
+ "is ${:.2f}\n".format
(weekly_salary_for_manager))
#Define the function getHourlyWorkerWeeklyPay() to
#calculate and display the weekly pay for the hourly
#worker.
def getHourlyWorkerWeeklyPay(hourly_wage, hours_worked):
weeklyPayForHourlyWorker = 0.0
#If the total hours worked is less than or equal to
#40.
if(hours_worked <= 40):
#Calculate the weeklyPayForHourlyWorker by
#muliplying hourly wages with total hours
#worked.
weeklyPayForHourlyWorker = hourly_wage * \
hours_worked
#Otherwise,
elif(hours_worked > 40):
#Multiply the remaining working hours after the
#initial 40 hours with the 1.5 times the hourly
#wages.
weeklyPayForHourlyWorker = (hours_worked - 40) * \
1.5 * hourly_wage
#Display the final weekly pay for hourly workers.
print("\nThe weekly pay for hourly workers "
+ "is ${:.2f}\n".format(weeklyPayForHourlyWorker))
#Define the function getWeeklyPayForCommissionWorker()
#to calculate and display the weekly pay for the
#commission worker.
def getWeeklyPayForCommissionWorker(gross_weekly_sales):
weeklyPayForCommissionWorker = 0.0
#Add 250 to the 5.7% of the gross weekly sales.
weeklyPayForCommissionWorker = 250 + 0.057 * \
(gross_weekly_sales)
#Display the final weekly pay for commission workers.
print("\nThe weekly pay for the commission workers "
+ "is ${:.2f}\n".format(weeklyPayForCommissionWorker))
#Define the function getWeeklyPayForPieceWorker() to
#calculate and display the weekly pay for the
#pieceworker.
def getWeeklyPayForPieceWorker(rate_per_item,
num_items_produced):
weeklyPayForPieceWorker = 0.0
#Multiply the price per item produced with the
#number of items produced.
weeklyPayForPieceWorker = rate_per_item * \
num_items_produced
#Display the final weekly pay for pieceworkers.
print("\nThe weekly pay for the pieceworkers "
+ "is ${:.2f}\n".format(weeklyPayForPieceWorker))
print("****** Employee Payment System ******")
#Start a while loop.
while True:
#Display the menu of choices.
print("1. Managers")
print("2. Hourly Workers")
print("3. Commission Workers")
print("4. Piece Workers")
#Prompt the user to enter a valid choice or -1 to
#quit.
userChoice = int(input("\nEnter your choice out "
+ "of the options given in the menu or enter -1 "
+ "to quit: "))
#If user choose -1, then break the loop.
if(userChoice == -1):
print("Bye!!!")
break
#If user's choice is 1, then prompt the user to
#enter the weekly salary for managers.
elif(userChoice == 1):
weekly_salary_for_manager = 0.0
weekly_salary_for_manager = float(input("Enter "
+ "the weekly sales: "))
#Call the function getManagerPay() and pass the
#value weekly_salary_for_manager as argument.
getManagerPay(weekly_salary_for_manager)
#If user's choice is 2, then prompt the user to
#enter the hourly wages and number of hours an
#employee worked.
elif(userChoice == 2):
hourlyWages = float(input("Enter the hourly "
+ "wage for hourly workers: "))
totalHoursWorked = int(input("Enter the number "
+ "of hours worked: "))
#Call the function getHourlyWorkerWeeklyPay() by
#passing the hourlyWages and totalHoursWorked to
#the function as arguments.
getHourlyWorkerWeeklyPay(hourlyWages,
totalHoursWorked)
#If user's choice is 3, then prompt the user to
#enter the gross weekly sales for the commission
#employee.
elif(userChoice == 3):
grossWeeklySales = float(input("Enter the gross "
+ "weekly sales for the commission workers: "))
#Call the function
#getWeeklyPayForCommissionWorker() and pass the
#value grossWeeklySales as argument.
getWeeklyPayForCommissionWorker
(grossWeeklySales)
#If user's choice is 4, then prompt the user to
#enter the price for each item produced and number
#of items produced.
elif(userChoice == 4):
payRatePerItem = float(input("Enter the pay "
+ "rate per item produced: "))
numberOfPieces = int(input("Enter the number "
+ "of items produced: "))
#Call the function getWeeklyPayForPieceWorker()
#by passing the payRatePerItem and
#numberOfPieces as function arguments.
getWeeklyPayForPieceWorker(payRatePerItem,
numberOfPieces)
#Otherwise, display an appropriate message.
else:
print("\nInvalid Choice!\n")