Please send questions to st10@humboldt.edu .
#----
# example from CIS 130 Week 3 Lab - 1-31-07
# last modified: 02-05-07
# adapted from example in Section 3 of "How to Design Programs",
#    MIT Press, Felleison, Findler, Flatt, Krishnamurthi,
#    www.htdp.org (and adapted with permission in class reading
#    packet)
# adapted by: Sharon Tuttle
#-----

# found out that at $5 a ticket, 120 people showed up

# every dime (0.10) decrease in ticket price results in
#    a 15 person increase in attendance
# so, if ticket price is 4.90, 135 people show up (120 + 15)

# costs for a performance: $180 + (.04 per attendee)

# owner is interested in finding the profit per ticket
#    price (so she can find the optimal ticket price)

# dependencies:
# *   profit for a performance is revenue - cost
# *   revenue for a performance is ticket price times attendance
# *   costs for a performance: $180 + (.04 per attendee)
# *   Number of attendees is based on ticket price

#---------------------------------------------
# constract: attendance: number -> number
# purpose: determine the number of people who
#          will attend a performance based on
#          <ticket_price>
# examples: attendance(5) should 120
#           attendance(4.9) should be 135

def attendance (ticket_price):
    return 120 + ((15/.10) * (5.0 - ticket_price))

#---------------------------------------------
# contract: revenue : number -> number
# purpose: determine the revenue for a performance
#          when the ticket price is <ticket_price>
# examples: revenue(5) should be 600

def revenue (ticket_price):
    return ticket_price * attendance(ticket_price)

#---------------------------------------------
# contract: cost : number -> number
# purpose: to find out how much a performance
#          costs (for the owner) based on <ticket_price>
# examples: cost(5) should be 184.80

PERF_BASE_COST = 180
COST_PER_ATTENDEE = 0.04

def cost (ticket_price):
    return PERF_BASE_COST + (COST_PER_ATTENDEE *
                             attendance(ticket_price))

#---------------------------------------------
# contract: profit : number -> number
# purpose: determine the profit for a performance
#          ticket price of <ticket_price>
# examples: profit(5) should be 415.2

def profit (ticket_price):
    return revenue(ticket_price) - cost(ticket_price)