In [1]:
price_per_gallon = 4.50 # dollars per gallon
miles_per_year = 14000.0 # miles per year
In [2]:
def price_per_year(mpg):
return (miles_per_year / mpg) * price_per_gallon
In [3]:
# Compare fuel efficiencies between 15 mpg and 50 mpg
mpg_list = range(15, 51)
price_list = [price_per_year(mpg) for mpg in mpg_list]
In [4]:
def setup_graph(title='', x_label='', y_label='', fig_size=None):
fig = plt.figure()
if fig_size != None:
fig.set_size_inches(fig_size[0], fig_size[1])
ax = fig.add_subplot(111)
ax.set_title(title)
ax.set_xlabel(x_label)
ax.set_ylabel(y_label)
setup_graph(title='Cost per year for each mpg rating', x_label='mpg', y_label='price', fig_size=(14,8))
_ = plot(mpg_list, price_list)
In [5]:
price_per_year(29) - price_per_year(30)
Out[5]:
In [6]:
price_per_year(20) - price_per_year(25)
Out[6]:
In [7]:
price_per_year(25) - price_per_year(30)
Out[7]:
In [8]:
price_per_year(30) - price_per_year(35)
Out[8]:
In [9]:
price_per_year(35) - price_per_year(40)
Out[9]:
In [10]:
price_per_year(20) - price_per_year(30)
Out[10]:
In [11]:
price_per_year(25) - price_per_year(35)
Out[11]:
In [12]:
price_per_year(30) - price_per_year(40)
Out[12]:
In [13]:
price_per_year(40) - price_per_year(50)
Out[13]: