Please send questions to
st10@humboldt.edu .
# Contract: total_attendance: void -> void
# Purpose: to ask user to enter number attending
# each of an un-predetermined number of
# performances, until they enter a -1 to
# stop; then print to the screen the
# total attendance at all those performances
# Example: if when total_attendance() is called, the
# user types (when prompted) 10, 30, 20, -1,
# the program should print to the screen:
# The total attendance is: 60
def total_attendance():
# initializing needed variables
total_so_far = 0
num_performances = 0
# get first attendance
print "Please enter first attendance value, "
current_attendance = int(raw_input("...or any negative number " +
"to quit: "))
max_so_far = current_attendance
# adding up the total attendance at all performances
while (current_attendance >= 0):
total_so_far = total_so_far + current_attendance
num_performances = num_performances + 1
if (current_attendance > max_so_far):
max_so_far = current_attendance
# NOTE that the following would ALSO make total_so_far
# bigger by current_attendance:
# total_so_far += current_attendance
# get next attendance
print "Please enter next attendance value, "
current_attendance = int(raw_input("...or any negative number " +
"to quit: "))
# now print the total attendance
print "The total attendance is: " + str(total_so_far)
print "...over " + str(num_performances) + " performances"
print "...and the largest single attendance is: " + str(max_so_far)
# Contract: max_profit: number number number -> number
# Purpose: compute and return the lowest ticket price with the
# highest profit for ticket prices in the range
# from <lowest_price> to <highest_price> (inclusive
# I hope) with ticket prices <price_diff> apart
# Examples: max_profit(5.0, 5.0, .1) == 5.0
# max_profit(4.5, 5.0, .1) == 4.5
from profit_ex import *
def max_profit(lowest_price, highest_price, price_diff):
# initializing variables
curr_ticket_price = lowest_price
max_profit_so_far = profit(lowest_price)
max_profit_ticket_price = lowest_price
# check the profit for each ticket in the range,
# looking for the highest profit
while (curr_ticket_price <= highest_price):
curr_profit = profit(curr_ticket_price)
if (curr_profit > max_profit_so_far):
max_profit_so_far = curr_profit
max_profit_ticket_price = curr_ticket_price
curr_ticket_price = curr_ticket_price + price_diff
# return the ticket price for maximum profit!
return max_profit_ticket_price