python 之類比購物車

來源:互聯網
上載者:User

標籤:strip   end   ping   src   com   product   pen   序號   menu   

#全部小代碼在此product_list = [[‘Iphone7‘,5800],                [‘Coffee‘,30],                [‘疙瘩湯‘,10],                [‘Python Book‘,99],                [‘Bike‘,199],                [‘ViVo X9‘,2499]                ]shopping_cart = []salary = int(input("input your salary:"))while True:    menu = u‘‘‘       ------- Good Shopping ---------       \033[32;1m       1.  輸入序號買商品進入購物車       2.  輸入q列印購物清單退出       \033[0m‘‘‘    print(menu)    index = 0    for product in product_list:        print(index,product)        index +=1    choice = input(">>").strip()    if choice.isdigit(): #判斷是否為數字        choice = int(choice)        if choice >= 0 and choice < len(product_list):#商品存在            product = product_list[choice]#取到商品            if product[1] <= salary:#判斷能否買得起                shopping_cart.append(product)#加入購物車                salary -= product[1]#扣錢                print("added product "+ product[0] + "into shopping cart,your current balance"+ str(salary))                print("現在的餘額為 %d 元" % salary)                #print("jia ge shi " + product[haproxy.conf] + "yuan")            else:                print("買不起,窮逼!產品價格是"+str(product)[1]+"你還差錢"+str(product[1]-salary)+"錢")        else:            print("商品不存在")    elif choice == "q":        print("----已購買商品列表-----")        print("id 商品 數量 單價 總價")        for i in shopping_cart:            print(i)        print("您的餘額為:",salary)        print("------end------")        break    else:        print("無此選項!")

 

python 之類比購物車

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.