Compsci 6, Fall 2011, Classwork 4

PRINT Names and NetID of students in group (min 2, max 3)
Name: __________________________ NetID: _____________   Name: __________________________   NetID: _____________

Name: __________________________ NetID: _____________

Starting Python Programs

For the following problem, first discuss an algorithm to solve the problem and then second try writing Python code (on paper) to solve the problem.

Pricing the Movies

Consider the problem facing the owner of a movie theater who has complete freedom in setting ticket prices. The more he charges, the fewer the people who can afford tickets. In a recent experiment the owner determined a precise relationship between the price of a ticket and average attendance. At a price of $5.00 per ticket, 120 people attend a performance. Decreasing the price by a dime ($.10) increases attendance by 15. Unfortunately, the increased attendance also comes at an increased cost. Every performance costs the owner $180. Each attendee costs another four cents ($0.04). The owner would like to know the exact relationship between profit and ticket price so that he can determine the price at which he can make the highest profit.

  1. Consider the following outline of code for this problem in which the first function is complete, and most of the functions are missing code. Discuss how you would calculate the revenue, profit, cost and number of attendees at one performance. Then fill in the missing code.
  2. def profit (ticket_price): ''' return profit of a performance based on ticket price''' return revenue(ticket_price) - cost(ticket_price) def revenue(ticket_price): ''' compute the revenue of a performance based on ticket price''' def cost(ticket_price): ''' compute the cost of one performance''' def attendees(ticket_price): ''' compute the number of attendees for one performance''' def printInfo(ticket_price): ''' print all the information based on a ticket price''' print "Ticket Price is " + str(ticket_price) print "profit is " + str(profit(ticket_price)) print "revenue is " + str(revenue(ticket_price)) print "Cost is " + str(cost(ticket_price)) print "Number of attendees are " + str(attendees(ticket_price)) print printInfo(5.00)
  3. Give additional values with which to test the program to convince yourself the program is correct.


  4. Choose several reasonable values to test which one might yield the most profit.


  5. Choose several reasonable values to test which one might yield no profit.


  6. How does one find which ticket price would yield the most profit?