The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
I need help
Discuss I need help in the Python Programming forum on Dev Shed. I need help Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

October 24th, 2012, 07:53 PM
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 6
Time spent in forums: 3 h 59 m 3 sec
Reputation Power: 0
|
|
|
****Need Help Asap****
1) The program should prompt the user for three elements of information for each employee:
Last Name
Pay Rate
Hours Worked
2) The program should allow the user to enter as many employees as they wish. Tell you user how to either continue entering data, or to quit.
3) If a person works over 40 hours, those hours are considered over time hours and need to be paid at 1.5 times the pay rate
4) After each entry, display the Name and pay for that employee
5) Keep a running total of regular pay, overtime pay, regular hours and overtime hours – at the end of the program you will need to display the total payroll amounts.
Requirements:
1) Must contain a main function – this function will be responsible for controlling the loop, data entry, displaying the total pay for a particular person and accumulation
2) Must contain a value returning function that returns the regular pay for a person
3) Must contain a value returning function that returns the overtime pay for a person
4) Must contain a separate print function for printing totals
5) Do not use global variables, except the overtime multiplier can be a constant if you wish (the 1.5)
6) All dollar amount should be formatted properly with dollar sign, commas, and two decimal points
7) You should have at least one instance of decision logic (if/then)
Outputs:
While you loop your program should prompt
Enter Last Name: <Jones>
Enter Pay Rate: <8.00>
Enter Hours: <43>
(Assume they entered Jones 8.00 43)
Call your functions and then you should display something like this:
Jones: $96.00
Ask if they’d like to enter more or quit
….
Then, once the user quits, you will need to display the totals:
(… this is just an example….)
Total Regular Hours: 765
Total Overtime Hours: 65
Total Regular Pay $76,001.50
Total Overtime Pay $560.71
This is what i have so far
# Global constants
BASE_HOURS = 40 # Base hours per week
OT_MULTIPLIER = 1.5 # Overtime multiplier
# The main function gets the number of hours worked and
# the hourly pay rate. It calls either the calc_pay_with_OT
# function or the calc_regular_pay function to calculate
# and display the gross pay.
def main():
# Create a variable to control the loop
keep_going = 'y'
while keep_going == 'y':
# Get name the hours worked and the hourly pay rate.
last_name = input('Enter employees name: ')
hours_worked = float(input('Enter the number of hours worked: '))
pay_rate = float(input('Enter the hourly pay rate: '))
# Calculate and display the gross pay.
if hours_worked > BASE_HOURS:
calc_pay_with_OT(hours_worked, pay_rate)
else:
calc_regular_pay(hours_worked, pay_rate)
# The calc_pay_with_OT function calculates pay with
# overtime. It accepts the hours worked and the hourly
# pay rate as arguments. The gross pay is displayed.
def calc_pay_with_OT(hours, rate):
# Calculate the number of overtime hours worked.
overtime_hours = hours - BASE_HOURS
#Calculate the amount of overtime pay.
overtime_pay = overtime_hours * rate * OT_MULTIPLIER
# Calculate the gross pay.
gross_pay = BASE_HOURS * rate + overtime_pay
# Display the gross pay.
print('The gross pay is $', format(gross_pay, ',.2f'), sep='')
# The calc_regular_pay function calculates pay with
# no overtime. It accepts the hours worked and the hourly
# pay rate as arguments. The gross pay is displayed.
def calc_regular_pay(hours, rate):
# Calculate the gross pay.
gross_pay = hours * rate
# Display the gross pay.
print('The gross pay is $', format(gross_pay, ',.2f'), sep='')
# Call the main function.
main()
Last edited by jwhit1984 : October 24th, 2012 at 09:44 PM.
Reason: NO ANSWER
|

October 24th, 2012, 09:48 PM
|
 |
Contributing User
|
|
|
|
Code:
# an untested program in python3 intended to conform with the instructions somewhat more than did the original
# Global constants
BASE_HOURS = 40 # Base hours per week
OT_MULTIPLIER = 1.5 # Overtime multiplier
# compute and return overtime pay
def calc_pay_with_OT(hours, rate):
# Calculate the number of overtime hours worked.
overtime_hours = max(0, hours - BASE_HOURS) # implicit "if" statement here
overtime_pay = overtime_hours * rate * OT_MULTIPLIER
return overtime_pay
# compute and return regular time pay
def calc_regular_pay(hours, rate):
regular_hours = min(hours, BASE_HOURS) # implicit "if" statement here
regular_pay = regular_hours*rate
return regular_pay
# The main function gets the number of hours worked and
# the hourly pay rate. It calls either the calc_pay_with_OT
# function or the calc_regular_pay function to calculate
# and display the gross pay.
def main():
# Create a variable to control the loop
keep_going = 'y'
total_overtime_pay = total_regular_pay = 0
while keep_going == 'y':
# Get name the hours worked and the hourly pay rate.
last_name = input('Enter employees name: ')
hours_worked = float(input('Enter the number of hours worked: '))
pay_rate = float(input('Enter the hourly pay rate: '))
# Calculate and display the gross pay.
regular_pay = calc_regular_pay(hours_worked,pay_rate)
overtime_pay = calc_pay_with_OT(hours_worked,pay_rate)
total_regular_pay += regular_pay
total_overtime_pay += overtime_pay
gross_pay = regular_pay + overtime_pay
# Display the gross pay.
print('The gross pay is $', format(gross_pay, ',.2f'), sep='')
keep_going = input('enter y to continue')
print('total regular pay is',total_regular_pay
# Call the main function.
main()
__________________
[code] Code tags[/code] are essential for python code!
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|