Compsci 6, Fall 2011, Classwork 3

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

Name: __________________________ NetID: _____________

Starting Python Programs

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

  1. Adding Time

    Consider the problem of adding units of measure together (like minutes and seconds). When you add the smaller units, e.g., seconds, they may "overrun" into the larger unit, e.g., minutes, you must update the larger unit and remove its value from the seconds total. For example, adding 20 seconds to 30 seconds results in 50 total seconds. But adding 20 seconds to 50 seconds, results in 1 minute and 10 seconds.

    1. Write a program to add time, i.e., adds together minutes and seconds and outputs the result in hours, minutes, and seconds
    2. What cases might you try to determine if your program works?
    3. How would you change your program to add distances, i.e., adds together feet and inches and outputs the result in miles, feet, and inches?
    4. How would you change your program to add money, i.e., adds together English shillings and pence and outputs the result in pounds, shillings, and pence?
    5. Write a general Python method to add any two units together

       























  2. 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. Describe an algorithm that computes the theater's profit based on a given ticket price.
    2. Choose several reasonable values to test which one might yield the most profit.
    3. Choose several reasonable values to test which one might yield no profit.
    4. Describe an algorithm to find which ticket price would yield the most profit.