Isst Drivs

OK, so your program should now be able to find the price, no matter where it appears in the page.

The frite e*t*-afrted fvo"1 ■the lavgev stvinoj oi HTML

It works! By adding very little extra code, you have made the program much smarter and more useful.

frugality feature

The new version of the program works, but now there's a design issue.

The Starbuzz CEO wants to know when the price of the beans falls below $4.74. The program needs to keep checking the Beans'R'Us website until that happens. It's time to restructure the program to add in this new feature.

Let's add a loop to the program that stops when the price of coffee is right.

Code Magnets

The program code to add the feature is sitting on the fridge door. Your job is to arrange the magnets so that the program loops until the price falls to $4.74 or lower.

http://www.beans-r-us.biz/prices.html")"/>
page = urllib.request.urlopen("http://www.beans-r-us.biz/prices.html")

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 j while price > 4.74: |

a page = urllib.request.urlopen("http://www.beans-r-us.biz/prices.html")

Pid you

*-ew>ew>be*" J ■to indent \ these lines? \ They ave inside the loop-

price = text[start_of_price:end_of_price]

\Zrhis Vme shouldn't be indented, as «t* outside the Up-

Was this article helpful?

0 0

Post a comment