What does the new program need to do

The new program for Starbuzz needs to give the user two options.

The first option is to watch and wait for the price of coffee beans to drop. If the user chooses this option, the program should run exactly as it did before.

The second option is for the user to place an emergency order. If the user chooses this option, the program should immediately display the current price from the supplier's website.

Here's the existing code for Starbuzz. You need to modify the program to add an emergency report feature that will immediately report the current price. Which parts of the code can you reuse to generate the emergency report? Grab your pencil and circle the part of the code you think you might reuse. Why do you think you'll need to resuse this code?

import urllib.request import time price = 99.99 while price > 4.74:

time.sleep(900)

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

price = float(text[start_of_price:end_of_price])

reuse code

Here's the existing code for Starbuzz. You needed to modify the program to add an emergency report feature which will immediately report the current price. Which parts of the code can you reuse to generate the emergency report? You were to circle the part of the code you think you might reuse as well as state why you might need to reuse it:

import urllib.request import time price = 99.99 while price > 4.74:

time.sleep(900)

Here's the code you can reuse.

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 price = float(text[start_of_price:end_of_price])

Wether you wait £>r the *9ht pride or revest an emergency order, yol/|| ,eed this ¿ode in eadh ¿ase.

If you just copy and paste the same code, it could make your program very long. And hard to maintain. That's why you don't want to duplicate the code.

Imagine if you had to maintain a program this length.

Was this article helpful?

0 0

Post a comment