I have to create a python program for class-
the instructions are-
Write a payroll program that pays time and a half for anything over 40 hours. This should have 3 functions in #addition to main.
Which I did without the 3 funcitons.
def main():
hours = float(input('How many hours did you work: '))
while hours < 8 or hours > 86:
print ("Error- Hours must be at least 8 and less than 86")
hours = float(input('re-enter hours worked: '))
rate = float(input('What is your hourly rate? '))
while rate < 7 or rate > 50:
print ("Error- Payrate must be at least $7.00 and less than $50.00")
rate = float(input('re-enter your hourly rate: '))
if hours <= 40:
print (" Payroll Information")
print ("Pay rate $",format(rate,'7.2f'))
print ("Regular Hours ", format (hours, '2.0f'))
print ("Overtime Hours 0")
print ("Regular pay $", format (hours*rate, '7.2f'))
print ("Overtime pay $ 0.00")
print ("Total pay: $", format (hours*rate, '7.2f'))
else:
othours = hours - 40
otpay = othours * (rate * 1.5)
regularpay = 40 * rate
print (" Payroll Information")
print ("Pay rate $", format (rate,'7.2f'))
print ("Regular Hours ", format (hours, '2.0f'))
print ("Overtime Hours ", format (othours, '2.0f'))
print ("Regular pay $", format (hours*rate, '7.2f'))
print ("Overtime pay $", format (otpay, '7.2f'))
print ("Total pay: $", format (regularpay+otpay,'7.2f'))
main()
Output
How many hours did you work: 50
What is your hourly rate? 8
Payroll Information
Pay rate $ 8.00
Regular Hours 50
Overtime Hours 10
Regular pay $ 400.00
Overtime pay $ 120.00
Total pay: $ 440.00
But now the teacher is hitting me with these instructions and I can't figure out how to seperate things to make him happy. When I start to seperate functions I get errors, or nothing prints.
- The first function asks the user how many total hours were worked and the pay rate and returns this information to main. These values must be validated. Hours worked must be at least 8 and no more than 86. Pay rate cannot be less than $7.00 or more than $50.00.
- The second function calculates the regular hours and overtime hours and returns this information to main. A person might work less than 40 hours so you must allow for that situation.
- The third function calculates the regular pay, (regular hours times pay rate); overtime pay, (overtime hours times overtime pay rate) and the total pay and returns this information to main.
- Main will then display this information on the screen like the sample below. (Values will have to be #passed and returned).