Page 118 -
P. 118

functions


                           Code Magnets

                           Before you amend the existing coffee bean program code, let’s
                           see if you can create a function to display the current bean price.
                           Rearrange the magnets in the correct order to create the function:













                                                                               We’ve given you a head start
                                                                               by adding the first magnet.




                      page = urllib.request.urlopen("http://www.beans-r-us.biz/prices.html")
                      text = page.read().decode("utf8")
                      where = text.find('>$')
                      start_of_price = where + 2
                      end_of_price = start_of_price + 4























                                                                                              :


                                                                                        get_price()
           import urllib.request
                                       get_price()
                                                               )       text[start_of_price:end_of_price]
                           print(                   def

                                                                                        you are here 4    83
   113   114   115   116   117   118   119   120   121   122   123