Python Error

Asked 2 years ago, Updated 2 years ago, 18 views

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

2022-09-22 16:17

1 Answers

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.


2022-09-22 16:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.