'''
Created on Sep 16, 2013

@author: rcd
'''
# An example to show how functions can help break down a problem
def revenue (ticket_price):
    return numAttendees(ticket_price) * ticket_price

def showCost (ticket_price):
    return 180 + 0.04 * numAttendees(ticket_price)

def numAttendees (ticket_price):
    return 120 + (15 / 0.10) * (5 - ticket_price)

def ticketProfit (price):
    """
    return float representing the profit taken in by the theater,
    dependent on float parameter price.
    """
    # TODO: complete code here
    return revenue(price) - showCost(price)


# find the price that maximizes the profit
                                    # "pattern" or template for finding extreme value
greatest = 0                        # initialize result to minimum value
for value in range(100, 600, 10):   # loop
    price = value / 100.0
    profit = ticketProfit(price)    # calculate current value
    if profit > greatest:           # compare against best of all previous values
        greatest = profit           #   replace if better

# show result
print(greatest)
