import urllib.request
price=99
while price > 5:
page=urllib.request.urlopen(
"http://beans-r-us.appspot.com/prices.html")
text=page.read().decode("utf-8")
start=text.find(">$")+2
end=start+4
price=text[start:end]
print(price)
if float(price) > 5.5:
print("Wait")
else:
print("Buy")
I know how to fix this program correctly I want to know what's wrong with this program and what's causing the error.
python
Price is initialized to 99 and is a numeric type.
However, while running price=text[start:end]
in the middle, the price type becomes a string.
Therefore, while price > 5
results in an error when comparing strings and integers.
© 2024 OneMinuteCode. All rights reserved.