from urllib.request import urlopen
page1 = urlopen("http://www.beans-r-us.biz/prices.html")
page2 = urlopen("http://www.beans-r-us.biz/prices-loyalty.html")
text1 = page1.read().decode("utf8")
text2 = page2.read().decode("utf8")
where = text2.find(">$")
start_of_price = where + 2
end_of_price = where + 6
price_loyal = text2[start_of_price:end_of_price]
price = text1[234:238]
password = 5501
p = input("Loyalty Customers Password? : ")
passkey = int(p)
if passkey == password:
while price_loyal > 4.74:
if price_loyal < 4.74:
print("Here is the loyal customers price :) :")
print(price_loyal)
else:
print( "Price is too high to make a profit, come back later :) ")
else:
print("Sorry incorrect password :(, here is the normal price :")
print(price)
input("Thanks for using our humble service, come again :), press enter to close this window.")
我遇到的问题是它一直运行直到我得到 4.74 部分。然后它停止并抱怨不可排序的类型。我完全不明白这意味着什么。
price_loyal
是一个字符串(即使它包含您通过以下方式找到的数字)find
)您试图与数值(4.75)进行比较?为了您的比较尝试
float(price_loyal)
UPDATE(感谢@agf):
使用Pythonv 3.x您收到您提到的错误消息。
>>> price_loyal = '555.5'
>>> price_loyal > 5000.0
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
price_loyal > 5000.0
TypeError: unorderable types: str() > float()
>>>
whereas
>>> float(price_loyal) > 5000.0
False
在这种情况下,Python 的版本会有所不同,因此始终提及正在使用的版本可能是个好主意。以前...使用Pythonv 2.x
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)