#author:yangxiao
'''
購物車需求
用戶入口:
1.商品信息存在文件里
2.已購商品,余額記錄。第一次啟動程序時需要記錄工資,第二次啟動程序時談出上次余額
3.允許用戶根據(jù)商品編號購買商品
4.用戶選擇商品后,檢測是否夠,夠就直接扣款,不夠就提醒
5.可隨時退出,退出時,打印移購買商品和余額
商家入口:
1.可以添加商品,修改商品價格
'''
import os,sys
def user_shopping():
while True:
user_salary = input('請輸入你的充值金額:')
if user_salary.isdigit():
user_salary = int(user_salary)
user_shop_file.write(login_name + '\t')
user_shop_file.write(str(user_salary) + '\n')
for item in product_lists:
print(product_lists.index(item),item)
p_index = product_lists.index(item)
while True:
user_choice = input('請輸入你要選擇的商品:')
if user_choice.isdigit():
user_choice = int(user_choice)
if user_choice <= p_index or user_choice >= 0:
p_item = product_lists[user_choice]
p_item[1] = int(p_item[1])
if user_salary >= p_item[1]:
user_salary -= p_item[1]
global shop_lists
shop_lists.append(p_item)
user_shop_file.seek(0)
user_shop_file.write(login_name + '\t')
user_shop_file.write(str(user_salary) + '\n')
print('商品%s已加入購物車,您還剩%s錢'%(p_item[0],user_salary))
else:
print('您的金額不錯,請去充值')
print('您已購得'.center(30,'*'))
print(shop_lists)
sys.exit()
else:
print('請輸入范圍內(nèi)的商品:')
elif user_choice == 'q':
sys.exit('退出程序')
else:('其輸入正確的商品編號')
else:
print('請輸入正確的格式')
def user_top():
while True:
user_salary = input('請輸入你要充值的金額:')
if user_salary.isdigit():
user_salary = int(user_salary)
user_salary += int(shop[1])
user_shop_file.seek(0)
user_shop_file.write(login_name + '\t')
user_shop_file.write(str(user_salary) + '\n')
for item in product_lists:
print(product_lists.index(item),item)
p_index = product_lists.index(item)
while True:
user_choice = input('請輸入你要購買的商品:')
user_choice = int(user_choice)
if user_choice <= p_index or user_choice >= p_index:
p_item = product_lists[user_choice]
p_item[1] = int(p_item[1])
if p_item[1] <= user_salary:
user_salary -= p_item[1]
global shop_lists
shop_lists.append(p_item)
user_shop_file.seek(0)
user_shop_file.write(login_name + '\t')
user_shop_file.write(str(user_salary) + '\n')
print('商品%s已加入購物車,您還剩%s錢'%(p_item[0],user_salary))
else:
print('您的金額不錯,請去充值')
print('您已購得'.center(30,'*'))
print(shop_lists)
sys.exit()
else:
print('請輸入正確的商品范圍')
else:
print('請輸入爭取的格式的格式')
user_name = ''
shop_lists = []
product_lists = []
def product_shop():
user_product_list_file = open('product_file.txt','r+',encoding ='UTF-8')
product_list_item = user_product_list_file.readlines()
for i in product_list_item:
i = eval(i)
product_lists.append(i)
product_shop()
print(product_lists)
user_shop_file =open('user_shop_file.txt','r+')
user_shop_list =user_shop_file.readlines()
for i in user_shop_list:
shop = i.split()
if len(user_shop_list) == 0:
login_name = input('請輸入用戶名:')
user_info_file = open('user_info_file.txt','r+')
user_info_list = user_info_file.readlines()
for a in user_info_list:
a = a.split()
if login_name in a:
while True:
login_pwd = input('請輸入密碼')
if login_pwd == a[1]:
print('歡迎進入購物商城')
user_shopping()
else:
print('你輸入的密碼不爭取')
else:
sys.exit('用戶名不存在')
else:
login_name = input('請輸入用戶名:')
user_info_file = open('user_info_file.txt','r+')
user_info_list = user_info_file.readlines()
for a in user_info_list:
a = a.split()
if login_name in a:
while True:
login_pwd = input('請輸入密碼')
if login_pwd == a[1]:
print('歡迎進入購物商城')
user_top()
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
分享文章:python學(xué)習(xí)之登陸購物-創(chuàng)新互聯(lián)
文章源于:http://jinyejixie.com/article26/coeojg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化、網(wǎng)站排名、云服務(wù)器、電子商務(wù)、網(wǎng)站營銷、品牌網(wǎng)站建設(shè)
聲明:本網(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)
猜你還喜歡下面的內(nèi)容