Please send questions to st10@humboldt.edu .

# Week 4 lecture examples
# last modified: 2-5-07

# contract: is_overtime: number -> bool
# purpose: returns true if <hours> is more than
#          OVERTIME_START, and returns false otherwise
# examples: is_overtime(20) == False
#           is_overtime(40) == False
#           is_overtime(60) == True

OVERTIME_START = 40

def is_overtime(hours):
    # (note: an expression in an unclosed set of
    #    parentheses can be continued on the next
    #    line
    
    return (hours >
           OVERTIME_START)

# contract: net_wages: number number -> number
#
# purpose: determine the net wages for a employee when
#          given his/her <hourly_wage> and the number
#          of <hours> worked; but a worker who works
#          more than 40 hours gets overtime of
#          time-and-a-half for all hours over 40
#
# examples: net_wages(12, 20) == 240
#           net_wages(12, 40) == 480
#           net_wages(12, 60) == 840

OVERTIME_FACTOR = 1.5

def net_wages(hourly_wage, hours):
    if is_overtime(hours):
        return ((OVERTIME_START * hourly_wage) +
                (hours - OVERTIME_START) *
                (hourly_wage * OVERTIME_FACTOR))
    else:
        return hourly_wage * hours