Skip to content

Instantly share code, notes, and snippets.

@davipatti
Created October 6, 2022 18:36
Show Gist options
  • Save davipatti/f6e98d310ec848c4206231553a35c31b to your computer and use it in GitHub Desktop.
Save davipatti/f6e98d310ec848c4206231553a35c31b to your computer and use it in GitHub Desktop.
#!usr/bin/env python3
def attendance(price: int):
"""Number of people that will attend for a given price."""
formula = 120 - ((price - 5) / 0.1) * 15
return max((formula, 0))
def cost_of_performance(n_people: int) -> float:
"""Cost in dollars of performance."""
return 180 + 0.04 * n_people
def ticket_sales_of_performance(n_people: int, price: float) -> float:
"""How much does the performance make?"""
return price * n_people
def profit(price: float) -> float:
"""The amount of profit to expect given a certain price."""
n_people = attendance(price)
return ticket_sales_of_performance(n_people, price) - cost_of_performance(n_people)
prices = [x / 10 for x in range(100)]
print(max(prices, key=profit))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment