ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 12 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 09 May 2017 My Price 9.00

Write a payroll program

Python Programming:

Write a payroll program that:

Prompts for the number of employees

Inputs the names, wage rates and hours for each employee

Calculates the wage

Displays the name, hours, rate and wage

Use lists for employee names, rates, hours and wages

The payroll program should also catch the following errors in the employee data that is entered:

User enters the wrong type of data (i.e. enters a string when and integer is expected)

User enters a zero-length name (i.e. simply presses the enter key when prompted for a name)

User enters a wage rate less than 0 or greater than 20

User enters weekly hours less than 0 or greater than 60

You do not need to do any input validation on the number of employees (i.e. the very first input)

When an error is caught, the user should be repeatedly prompted until they enter the correct value.

Use the incomplete Python file: Assn 05 Prb 01 Start.py as the start of your program. Add to this file to complete the problem requirements. Do not move or delete any parts of the program. Be sure to use the exception and function names as shown.

The program should display output as shown as below.

>>>

**************** Payroll Program ****************

****************   Data Input    ****************

Please enter the number of employees: 3

Data entry for employee 0

Enter the employee name:

'Name cannot be zero length'

Please start over

Data entry for employee 0

Enter the employee name: aaa

Enter the employee wage rate (0..20): I am a string!

Data entered in incorrect format

Please start over

Data entry for employee 0

Enter the employee name: aaa

Enter the employee wage rate (0..20): -33

'Hourly rate must between 0 and 20'

Please start over

Data entry for employee 0

Enter the employee name: aaa

Enter the employee wage rate (0..20): 20

Enter the employee hours (0..60): 1000

'Hours must between 0 and 60'

Please start over

Data entry for employee 0

Enter the employee name: aaa

Enter the employee wage rate (0..20): 20

Enter the employee hours (0..60): 20

Data entry for employee 1

Enter the employee name: bbb

Enter the employee wage rate (0..20): 18

Enter the employee hours (0..60): 30

Data entry for employee 2

Enter the employee name: ccc

Enter the employee wage rate (0..20): 16

Enter the employee hours (0..60): 40

**************** Payroll Data ****************

Employee: aaa

   Hours: 20.0

   Rate: $20.0/hr

   Wage: $400.0

Employee: bbb

   Hours: 30.0

   Rate: $18.0/hr

   Wage: $540.0

Employee: ccc

   Hours: 40.0

   Rate: $16.0/hr

   Wage: $640.0

>>>

Assn 05 Prb 01 Start.py :

def main():
print("**************** Payroll Program ****************")
print()
print("**************** Data Input ****************")
numEmployees = int(input("Please enter the number of employees: "))
print()
employeeNames = []
employeeRates = []
employeeHours = []
employeeWages = []

for employeeNumber in range(numEmployees):
while True:

try:
name = readName()
rate = readRate()
hours = readHours()   


else:
employeeNames.append(name)
employeeRates.append(rate)
employeeHours.append(hours)
employeeWages.append(employeeHours[employeeNumber] * employeeRates[employeeNumber])
print()
break
print()
print()

print()
print("**************** Payroll Data ****************")
for employeeNumber in range(numEmployees):
print("Employee: {}".format(employeeNames[employeeNumber]))
print(" Hours: {}".format(employeeHours[employeeNumber]))
print(" Rate: ${}/hr".format(employeeRates[employeeNumber]))
print(" Wage: ${}".format(employeeWages[employeeNumber]))
print()

# Thrown if employee name is zero length
class EmpNameError(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)

# Thrown if hourly rate <0 or > 20
class RateError(Exception):

# Thrown if weekly hours <0 OR > 60
class HoursError(Exception):


# function readName


# function readRate


# function readHours

if __name__ == "__main__": main()

Answers

(11)
Status NEW Posted 09 May 2017 05:05 AM My Price 9.00

-----------

Not Rated(0)