'''
Created on Feb 10, 2014

@author: rcd
'''
# An example to show how functions can help break down a problem
def ticketProfit (price):
    """
    return float representing the profit taken in by the theater,
    dependent on float parameter price.
    """
    def numAttendees (ticketPrice):
        return 120 + (15 / 0.10) * (5 - ticketPrice)
    def revenue (ticketPrice):
        return numAttendees(ticketPrice) * ticketPrice
    def costForShow (ticketPrice):
        return 180 + 0.04 * numAttendees(ticketPrice)
    return revenue(price) - costForShow(price)


# find the price that maximizes the profit
                                       # template for finding extreme value
maxPrice = 0                           # initialize result to minimum value
maxProfit = 0
for price in range(100):               # loop
    priceFloat = price/10.0
    profit = ticketProfit(priceFloat)  # calculate current value
    if profit > maxProfit:             # compare against best of all previous values
        maxProfit = profit             #   replace if better
        maxPrice = priceFloat

print(str.format("${0:0.2f} generates ${1:0.2f}", maxPrice, maxProfit))


