Page 120 -
P. 120
functions
Test Drive
Type the code on the opposite page into IDLE, and run it to see what
happens:
When this code runs,
the price is displayed
right away. (Note: you
may see a different
price when you run your
code.)
The price appears immediately. You now have a function that reads the
contents of the page from the supplier’s website and prints out the price
information.
You can reuse the function in lots of places in your program simply by
calling the get_price() function. Now all you have to do is modify
your existing program to use the new function.
Look back at the original program at the start of the chapter. You know that you
can use this function to produce emergency reports. But it will also need to
replace the existing price-watch code. Is there a problem? Why? Why not?
you are here 4 85