Page 121 -
P. 121
limits of print
Your code prints out the price. Big
deal. It‛s just a pity you actually need
to GET the price and USE it. Your code
isn‛t much use, just printing out the
price like that, is it?
Functions are great for reusing code, but they
really come into their own when they perform
an action for you, then give you back some
data to use in whichever way you want.
The current version of the get_price() function prints out
the price of coffee beans every time it is used, or called. This
is OK if that’s what you really want it to do. The trouble is, you
need the function to give you the price so that you can then
decide what you want to do with it.
What's the
... current price?
discount = 0.9
print("The discounted price is: ")
price = get_price()
get_price()
actual_price = price * discount
print(str(actual_price))
...
5.51 The “get_price()"
function. Even the
name tells you a little
about what it does.
86 Chapter 3