《Head First Programming》---python 3_함수.

872 단어 함수.
함수.
import urllib.request
import time

def get_price():

    page = urllib.request.urlopen("http://www.laofengxiang.com/index.php")
    text = page.read().decode("utf8")
    #print(text)
    where = text.find("  : ")
    #print(where)
    start_of_price = where + 4;
    #print(start_of_price)    
    end_of_price = start_of_price + 3
    #print(end_of_price)   
    #print(text[start_of_price:end_of_price])
    return (text[start_of_price:end_of_price])
    
price_now = input("Do you want to see the price now (Y/N) ? ")
if price_now == "Y":
    print(get_price())
else:
    price = float(get_price())
    while price > 499.9:
        time.sleep(3600) #  1      
        price = float(get_price())
    print("Price is ", price, " / ")
    print("Buy for my lover!")

좋은 웹페이지 즐겨찾기