i = ["iphone 6000", "bicycle 1000", "coffee 50", "python book 100", "italy pizza 200", ] j = ["] # 运用列表嵌套更容易实现 in_list = [] # 已购买物品列表 salary = int(input("你的工资:")) while salary > 0: # 循环的开始以工资余额大于零开始 # a = 0 # 循环打印利于管理员账户的管理 # while a < 5: # print("{xuhao}" .format(xuhao=a+1), i[a]) # 生硬的加个序号 下面注释的是更简单的方法 # a += 1 for d, e in enumerate(i, 1): print(d, ">>>", e) w_i = input("你想要的物品序号或者退出q") if w_i.isdigit(): # 判断是否数字(输入的都是字符串) w_i = int(w_i) if 0 < w_i <= len(i): # len 计算长度 if salary > int(j[w_i-1]): salary -= int(j[w_i-1]) # 余额变成工资 接着循环 in_list.append(i[w_i-1]) # 加入购物车列表 print(i[w_i-1], "已加入你的购物车") else: print("您的余额不足") elif w_i == "q": break elif w_i == "manager": print("0:增加商品 1:下架商品 2:修改价格 ") keyword = int(input("输入命令序号:")) if keyword == 0: name_staff = str(input("输入商品名")) ordor_staff = int(input("输入商品序号")) price_staff = input("输入价格") name_staff = " ".join([name_staff,price_staff]) j.insert(ordor_staff-1, price_staff) i.insert(ordor_staff-1, name_staff) elif keyword == 1: ordor_staff = int(input("输入商品序号")) l = i.pop(ordor_staff - 1) print("已删除:", l) elif keyword == 2: ordor_staff = int(input("修改的序号")) gai_price = input("修改的价格") j[ordor_staff-1] = gai_price f = i[ordor_staff-1] # iho 6000 u = j[ordor_staff - 1] # u =1 v = "".join([f,"降价为"]) i[ordor_staff-1] = " ".join([v,u]) else: print("眼瞎呀") else: print("非法字符") print("您已经购买:") for b in in_list: print(b) print("您的余额为:", salary)
简易购物车系统