I need to have 3 functions in addition to the main. I got a response before except it didn't have 3 functions. The 1st function asks the user how many hours were worked and the pay rate and returns this information to main. The second function calculates the regular hours and overtime hours and returns this information to main. The third function calculates the regular pay, (regular hours times pay rate); overtime pay, (overtime hours times 1.5 pay rate) and the total pay and returns this information to main. I've been working on this for a couple weeks but can't figure out how to set up the 3rd function and return it to the main. Please help. I have errors in lines 65, 41, 27.

``````def ask_hours():
hours = float(raw_input ("How many hours did you work? "))
rate = float(input ("What is your rate of pay? "))
return hours, rate

def findrate(hours, rate):
if hours >= 40:
hours1 = 40
ot = hours - 40
elif hours < 40:
hours2 = hours
ot1 = 0
return hours1, ot, hours2, ot1

def getpaid(pay):
if hours1 >= 40:
pay = hours1 * rate
ot3 = ot * 1.5
elif hours1 < 40:
pay = hours * rate
ot3 = 0
return pay, ot3

def main() :
findrate(hours, rate)
getpaid(pay)
print "Pay rate", rate
if hours >= 40:
print "Regular hours", hours
print "Overtime hours", ot
elif hours < 40:
print "Regular hours", hours2
print "Overtime hours", 0
if hours >= 40:
print "Regular pay", (40 * rate)
elif hours < 40:
print "Regular pay", (hours * rate)
if hours >= 40:
print "Overtime Pay", ot3
elif hours < 40:
print "Overtime Pay", 0
if hours >= 40:
print "Total Pay", (pay + ot3)
elif hours < 40:
print "Total Pay", (pay + 0)

main()``````
2
Contributors
3
Replies
4
Views
10 Years
Discussion Span
Last Post by strictlycustom

Study this and see if you can understand and learn:

``````def ask_hours():
hours = float(raw_input ("How many hours did you work? "))
rate = float(input ("What is your rate of pay? "))
return hours, rate

def find_hours(hours):
"""return regular and overtime hours"""
if hours >= 40:
reg_hours = 40
ot_hours = hours - 40
else:
reg_hours = hours
ot_hours = 0
return reg_hours, ot_hours

def calc_pay(reg_hours, ot_hours, rate):
"""return regular pay and overtime pay"""
reg_pay = reg_hours * rate
if ot_hours > 0:
ot_pay = ot_hours * 1.5 * rate
else:
ot_pay = 0
return reg_pay, ot_pay

def main() :
reg_hours, ot_hours = find_hours(hours)
reg_pay, ot_pay = calc_pay(reg_hours, ot_hours, rate)
print "Pay rate", rate
print "Regular hours", reg_hours
print "Overtime hours", ot_hours
print "Regular pay", reg_pay
print "Overtime Pay", ot_pay

main()``````

Using good variable names and documenting the functions will help you. Also please keep the indentations constant.

I'm definitely studying ZZ, but I am having an error if I worked less than 40 hours. I have a test coming up. I just have problems recalling the functions, I think I format them wrong.

``````def ask_hours():
hours = float(raw_input ("How many hours did you work? "))
rate = float(input ("What is your rate of pay? "))
return hours, rate

def find_hours(hours):
if hours >= 40:
reghours = 40
ot_hours = hours - 40
elif hours < 40:
reghours = hours
ot_hours = 0
return reghours, ot_hours

def calc_pay(reghours, ot_hours, rate):
reg_pay = reghours * rate
if ot_hours > 0:
otpay = ot_hours * 1.5 * rate
elif ot_hours < 0:
otpay = 0
total = reg_pay + otpay
return reg_pay, otpay, total

def main() :
reghours, ot_hours = find_hours(hours)
reg_pay, otpay, total = calc_pay(reghours, ot_hours, rate)
print "Pay rate", rate
print "Regular hours", reghours
print "Overtime hours", ot_hours
print "Regular pay", reg_pay
print "Overtime Pay", otpay
print "Total Pay", total

main()``````

Nevermind got it all figured out. Just takes some toying around with it to realize what I missed.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.