日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python购物车实现的功能是什么_Python3实现购物车功能

發(fā)布時間:2023/12/2 python 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python购物车实现的功能是什么_Python3实现购物车功能 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Python3實現(xiàn)購物車功能

來源:中文源碼網(wǎng)????瀏覽: 次????日期:2018年9月2日

【下載文檔:??Python3實現(xiàn)購物車功能.txt?】

(友情提示:右鍵點上行txt文檔名->目標另存為)

Python3實現(xiàn)購物車功能 本文實例為大家分享了Python3實現(xiàn)購物車功能的具體代碼,供大家參考,具體內(nèi)容如下購物車要求:

1、啟動程序后,輸入用戶名密碼后,如果是第一次登錄,讓用戶輸入工資,然后打印商品列表

2、允許用戶根據(jù)商品編號購買商品3、用戶選擇商品后,檢測余額是否夠,夠就直接扣款,不夠就提醒 4、可隨時退出,退出時,打印已購買商品和余額5、在用戶使用過程中, 關(guān)鍵輸出,如余額,商品已加入購物車等消息,需高亮顯示6、用戶下一次登錄后,輸入用戶名密碼,直接回到上次的狀態(tài),即上次消費的余額什么的還是那些,再次登錄可繼續(xù)購買7、允許查詢之前的消費記錄

邏輯圖:執(zhí)行代碼:#!/usr/bin/env python3

# Author: Robert

# --*-- coding: utf-8 --*--set = False #設置set 當輸入為q就可以退出

file = open("購物車用戶信息檔案.txt","r+",encoding="utf-8") #讀取購物車用戶信息文件

f = str(file.read()) #將文件內(nèi)容轉(zhuǎn)化成字符串

for line in f:

file_str = str(f)

data = eval(file_str) #將字符串轉(zhuǎn)換為字典dataname = input("輸入姓名:")

password = input("輸入密碼:")

while True:

if name in data: #用戶在檔案中

if password in data[name]: #密碼和用戶名對應,校驗正確,登錄。

salary = float(data[name][password])

print('''\033[32;1m歡迎登錄,當前余額為%s\033[0m'''%salary)

break

else: #否則密碼錯誤,請重新輸入

password = input("密碼錯誤,請重新輸入:")

continue

else: #否則判斷為首次登錄,將用戶名,密碼,工資存到用戶信息文件中

password_salary = {}

salary_str = input("歡迎首次登錄,請輸入你的工資:")

salary = float(salary_str)

password_salary[password] = salary #工資對應到密碼

data[name] = password_salary #將密碼-工資對應到用戶名

file.seek(0)

file.write(str(data))

file.tell()

breaklist = [#購物清單

["iphone",5800],

["sifei",800],

["macbook",17500],

["book",75],

["apple",5]

]file_list_r = open("歷史購物信息.txt","r+",encoding="utf-8")

file_list_r = str(file_list_r.read())

shoppinglist_dict = eval(file_list_r)

if name not in shoppinglist_dict:

shoppinglist_dict[name] = []

shoppinglist = shoppinglist_dict[name]

shoppinglist_dict_now = []

choose = input("\n是否需要查詢歷史購物記錄(y/n):")

if choose == 'y':

print("\n\n---------->歷史購物記錄 print(shoppinglist)

print("---------->結(jié)束 print("---------->商品清單 for index,item in enumerate(list,1):

print(index,item)

print("---------->結(jié)束 number = input("請輸入想購買商品編號:")

if number == "q":

set = True

data[name][password] = str(salary)

file.seek(0)

file.write(str(data))

file.tell()

print("---------->購物清單 print(shoppinglist)

print("您的余額:",salary)

print("---------->結(jié)束 shoppinglist.extend(shoppinglist)

shoppinglist_dict[name] = shoppinglist

elif number.isdigit() == False:

print("\033[31;1m輸入不是編號內(nèi)容,請重新輸入\033[0m")

elif int(number)>int(len(list)) or int(number)<= 0: #輸入值不在清單中,報錯

print("\033[31;1m您所購買的商品不在清單中\(zhòng)033[0m")

else:

number_buy = int(number)-1

if list[number_buy][1] salary = salary - int(list[number_buy][1])

msg = '\033[32;1m您已經(jīng)將%s加入購物車中,余額為%d\033[0m'%(list[number_buy][0],salary)

print(msg)

shoppinglist.append(list[number_buy]) #將本次購物信息加到購買記錄中

else:

print("\033[31;1m余額不足,無法購買!\033[0m") #提示余額不足

購物車用戶信息檔案.txt{'name': {'password': '10000'}, 'cx': {'123': '725.0'}, 'robert': {'qw': '440.0'}, 'cv1': {'1': 100.5}, 'ROBERT': {'QW': 1560.0}, 'qwe': {'qw': '1555.0'}}歷史購物信息.txt{'name': [['iphone', 5800],['bike', 800]], 'cx':[['iphone', 5800],['apple', 5],['apple', 5], ['book', 75]]}以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持中文源碼網(wǎng)。

親,試試微信掃碼分享本頁!?*^_^*

總結(jié)

以上是生活随笔為你收集整理的python购物车实现的功能是什么_Python3实现购物车功能的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。