這篇文章給大家分享的是有關(guān)python怎么實現(xiàn)購物車的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。

創(chuàng)新互聯(lián)公司專注于網(wǎng)站建設(shè),為客戶提供成都網(wǎng)站制作、網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計開發(fā)服務(wù),多年建網(wǎng)站服務(wù)經(jīng)驗,各類網(wǎng)站都可以開發(fā),品牌網(wǎng)站制作,公司官網(wǎng),公司展示網(wǎng)站,網(wǎng)站設(shè)計,建網(wǎng)站費用,建網(wǎng)站多少錢,價格優(yōu)惠,收費合理。
#!/usr/bin/env python
#!-- coding:utf-8 --
#Author:Eric
My_salary = input("Input your salary:")
if My_salary.isdigit():
My_salary = int(My_salary)
else:
exit("Invaild data type...")
welcome_msg = 'Welcome to Eric Shopping mall'.center(50,'-')
print(welcome_msg)
exit_flag = False
product_list = [
('Iphone',5800),
("Mac Air",8000),
("Mac Pro",9000),
("XiaoMi 2",19.9),
("Coffee",30),
("Tesla",820000),
("Bike",700),
("Cloth",200),]
shop_car = []
while exit_flag is not True:
#for product_item in product_list:
#p_name,p_price = product_item
print("product list".center(50,'-'))
for item in enumerate(product_list): #將列表中的下標進行返回。枚舉函數(shù)
index = item[0]
p_name = item[1][0]
p_price = item[1][1]
print (index,'.',p_name,p_price)
#print(len(product_list))
user_choice = input("[q = quit,c=check] What do you want to Buy?:")
if user_choice.isdigit(): #肯定是要選擇商品。
user_choice = int(user_choice)
if user_choice < len(product_list):
p_item = product_list[user_choice]
if p_item[1] <= My_salary:
shop_car.append(p_item) #放入購物車
My_salary -=p_item[1] #減錢
print("Added [%s] into shop car,your current balance is \033[31;1m[%s]\033[0m"
%(p_item,My_salary))
else:
print("Your balance is [%s],cannot afford this..." %[My_salary])
else:
if user_choice == 'q' or user_choice == 'quit':
print("purchased products as below".center(40,'*'))
for item in shop_car:
print(item)
print("END".center(40,'*'))
print('Your balance is [%s]' %My_salary)
exit_flag = True
if user_choice == 'c' or user_choice == 'check':
print("purchased products as below".center(40,'*'))
for item in shop_car:
print(item)
print("END".center(40,'*'))
print('Your balance is [%s]' %My_salary)感謝各位的閱讀!關(guān)于“python怎么實現(xiàn)購物車”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
當前文章:python怎么實現(xiàn)購物車
轉(zhuǎn)載來源:http://chinadenli.net/article16/jijsdg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供建站公司、定制網(wǎng)站、網(wǎng)站維護、營銷型網(wǎng)站建設(shè)、微信小程序、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)