在写这段脚本之前,一直卡了很久、刚开始不知道从何下手。慢慢努力就写出来了。不容易、继续加油!#_*_coding:utf-8_*_#购物车#注册入口# 用户入口:# 1.商品信息存在列表里 原本应该是存在文件里面但是感觉实际工作中此类数据源都应该存在数据库里面所以改为列表存储# 2。已购商品余额记录#商家入口# 1.可以添加商品,修改商品价格shoping = [ ["黑丝袜",100], ["超短迷你裙",200], ["连身裙",300], ["MacbookAir",10000], ["IphoneX",9999], ["特斯拉",1200000], ["无敌海景别墅",5000000], ["童颜巨乳大长腿",1000000], ["肤白貌美老婆一枚",100000]]shopinglist = []tab = []class Userlogon(object): def __init__(self,name,password,statry): self.name = name self.password = password self.statry = statry if self.statry >= 0 : print('商品列表'.center(100, "-")) print("编号".center(20, " "), "名称".ljust(40, " "), "价格".ljust(9, " ")) for index, i in enumerate(shoping): print(str(index).center(21, " "), str(i[0]).ljust(31, " "), str(i[1]).ljust(9, " ")) else: print("您太穷了,您还是去上班吧!!!!!!!!!!!") exit() while True: Choice = input("请按序号选择您需要购买的商品:") if Choice.isdigit(): Choice = int(Choice) if Choice < len(shoping) and Choice >= 0: s_list = shoping[Choice] if s_list[1] <= self.statry: self.statry -= s_list[1] shopinglist.append(s_list) print("您已经购买的商品如下:%s 您的余额为:%s" % (s_list[0], self.statry)) else: print("您的余额不足以购买该商品,请重新选择或者按q键退出程序..........") # elif Choice == 'q': # print(shopinglist) else: if Choice == "q": print("您购买的商品如下:%s 您的余额为: %s " % (shopinglist,self.statry)) exit()class Waiter(object): def __init__(self,name,Price): self.name = name self.Price = Price # name = input("您需要上架的商品:").strip() # Price = int(input("该商品的价格:")) for i in shoping: if i[0] == self.name and i[1] == self.Price: print("该商品已经存在,请问您是否继续添加该商品,如果您输入Y将继续添加,如果您输入N则退出改程序") y = input("请输入您的选择:") if y == 'y': shoping[0] = self.name shoping[1] = self.Price else: break else: print("这是一件新的商品,请问您是否上架,确定请按Y,退出请按N") y = input("请输入您的选择:") if y == 'y': shoping.append([self.name,self.Price]) print("您上架的商品为:%s ,该商品的价格为: %s" %(self.name,self.Price)) print('商品列表'.center(100, "-")) print("编号".center(20, " "), "名称".ljust(40, " "), "价格".ljust(9, " ")) for index, i in enumerate(shoping): print(str(index).center(21, " "), str(i[0]).ljust(31, " "), str(i[1]).ljust(9, " ")) else: print("系统退出...........") breakclass mod(object): def __init__(self,name,Price): self.name = name self.Price = Price for index,i in enumerate(shoping): if self.name == i[0]: i[1] = self.Price print("%s 的商品价格已经更改,更改之后的价格为: %s " %(self.name,self.Price)) print('商品列表'.center(100, "-")) print("编号".center(20, " "), "名称".ljust(40, " "), "价格".ljust(9, " ")) for index, i in enumerate(shoping): print(str(index).center(21, " "), str(i[0]).ljust(31, " "), str(i[1]).ljust(9, " "))Userlogon(101645,"password",100000)Waiter("泷泽萝拉",1000)mod("特斯拉",66666)