#author:yangxiao
'''
創(chuàng)新互聯(lián)-專(zhuān)業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性?xún)r(jià)比沿河網(wǎng)站開(kāi)發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式沿河網(wǎng)站制作公司更省心,省錢(qián),快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋沿河地區(qū)。費(fèi)用合理售后完善,十余年實(shí)體公司更值得信賴(lài)。
購(gòu)物車(chē)需求
用戶(hù)入口:
1.商品信息存在文件里
2.已購(gòu)商品,余額記錄。第一次啟動(dòng)程序時(shí)需要記錄工資,第二次啟動(dòng)程序時(shí)談出上次余額
3.允許用戶(hù)根據(jù)商品編號(hào)購(gòu)買(mǎi)商品
4.用戶(hù)選擇商品后,檢測(cè)是否夠,夠就直接扣款,不夠就提醒
5.可隨時(shí)退出,退出時(shí),打印移購(gòu)買(mǎi)商品和余額
商家入口:
1.可以添加商品,修改商品價(jià)格
'''
import os,sys
def user_shopping():
while True:
user_salary = input('請(qǐng)輸入你的充值金額:')
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('請(qǐng)輸入你要選擇的商品:')
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已加入購(gòu)物車(chē),您還剩%s錢(qián)'%(p_item[0],user_salary))
else:
print('您的金額不錯(cuò),請(qǐng)去充值')
print('您已購(gòu)得'.center(30,'*'))
print(shop_lists)
sys.exit()
else:
print('請(qǐng)輸入范圍內(nèi)的商品:')
elif user_choice == 'q':
sys.exit('退出程序')
else:('其輸入正確的商品編號(hào)')
else:
print('請(qǐng)輸入正確的格式')
def user_top():
while True:
user_salary = input('請(qǐng)輸入你要充值的金額:')
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('請(qǐng)輸入你要購(gòu)買(mǎi)的商品:')
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已加入購(gòu)物車(chē),您還剩%s錢(qián)'%(p_item[0],user_salary))
else:
print('您的金額不錯(cuò),請(qǐng)去充值')
print('您已購(gòu)得'.center(30,'*'))
print(shop_lists)
sys.exit()
else:
print('請(qǐng)輸入正確的商品范圍')
else:
print('請(qǐng)輸入爭(zhēng)取的格式的格式')
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('請(qǐng)輸入用戶(hù)名:')
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('請(qǐng)輸入密碼')
if login_pwd == a[1]:
print('歡迎進(jìn)入購(gòu)物商城')
user_shopping()
else:
print('你輸入的密碼不爭(zhēng)取')
else:
sys.exit('用戶(hù)名不存在')
else:
login_name = input('請(qǐng)輸入用戶(hù)名:')
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('請(qǐng)輸入密碼')
if login_pwd == a[1]:
print('歡迎進(jìn)入購(gòu)物商城')
user_top()