Page 97 -
P. 97
Code Magnets Solution
The program code to add the feature was sitting on the fridge door.
You were asked to arrange the magnets so that the program loops
until the price falls to $4.74 or lower.
import urllib.request
price = 99.99
while price > 4.74:
page = urllib.request.urlopen("http://www.beans-r-us.biz/prices.html")
Did you text = page.read().decode("utf8")
remember
to indent
these lines? where = text.find(‘>$’)
They are
inside the start_of_price = where + 2
loop.
end_of_price = start_of_price + 4
price = text[start_of_price:end_of_price]
print ("Buy!")
This line shouldn’t
be indented, as it's
outside the loop.
62 Chapter 2