7. Strings are different from numbers¶

7.1. Convert to float
¶
11
from urllib.request import urlopen
URL_LOYALTY_PRICES = "https://api.allorigins.win/raw?url=http://beans.itcarlow.ie/prices-loyalty.html"
page = urlopen(URL_LOYALTY_PRICES)
text = page.read()
location = text.find(">$")
start = location + 2
end = start + 4
if float(text[start:end]) < 4.74:
print("Buy! price: %5.2f" % float(text[start:end]))
Activity: 7.1.1 ActiveCode (ac_l33_7a_en)
7.2. Can you keep testing the price?¶

7.3. Can you keep trying?¶
13
from urllib.request import urlopen
URL_LOYALTY_PRICES = "https://api.allorigins.win/raw?url=http://beans.itcarlow.ie/prices-loyalty.html"
price = 99.99
while price >= 4.74:
page = urlopen(URL_LOYALTY_PRICES)
text = page.read()
location = text.find(">$")
start = location + 2
end = start + 4
price = float(text[start:end])
print("Buy! price: %5.2f" % price)
Activity: 7.3.1 ActiveCode (ac_l33_7b_en)
7.4. The CEO is very happy!¶

You have attempted 1 of 3 activities on this page