import urllib.request
import time
def get_price():
page = urllib.request.urlopen("http://beans-r-us.appspot.com/prices-loyalty.html")
text = page.read().decode("utf8")
where = text.find(">$")
start_of_price = where + 2
end_of_price = start_of_price + 4
price = text[start_of_price:end_of_price]
return(price)
def cheap_price():
while float(price) > 4.74:
time.sleep(1)
price = get_price()
print("$" + price)
print("buy!")
custom_setting = "End"
return(custom_setting)
custom_setting = input("Do you want custom setting?(Y/N)")
while custom_setting == "Y" :
custom_setting = input("Do you want price now?(Y/N)")
if custom_setting == "Y":
price = get_price()
print("$" + price)
else:
cheap_price()
custom_setting = cheap_price()
while custom_setting == "N" :
cheap_price()
custom_setting = cheap_price()
print("Perfect End")
작동은하는데 에러는 안뜨는데 최종적으로 Perfect End나와야는데 안뜨네요.
게다가 N분기로가면
가격도 두번나오고 한번나와야되는데 여러번나오는데 custom_setting = "End"로 함수에서 변수로 return이 지정되지도않고요.
- dc official App
일단 뭐하는 코드인지 모르겠음
당장 문제점을 찾자면 cheap_price에서 while을 도는 부분이 있는데 price 값이 변하지 않으니까 무한루프를 돌게됨
책보고 따라하는건데 저 사이트에서 가격만 따로 뽑아서 출력하는 파이썬코드에요. 함수부분에 price 순서가 바뀌었네요. - dc App
순서 바뀐 부분이 많아보이고 변수가 이름에 맞는 일을 안함
그리고 마지막 질문인 함수 내부에서 대입 연산이 함수 밖에서 유지되지 않는다. 인데 이게 맞음 파이썬은 원래 그럼
지금 열심히 해결하다가 덕분에 버그가 뭐때문에 일어났는지 알게됬어요. 감사합니다. - dc App