#__author:ocean #Practice makes Perfect #date: 2018/3/30 print("欢迎使用购物车程序.") salary = 5000 list = ['iphone6s','mac book','coffee','python book','bicyle'] price= [5800,9000,32,80,1500] list2=[] price2=[] flag = "f" while flag !="Q" and flag!="q": msg=''' ------------商店------------ 1. iphone6s %s 2. mac book %s 3. coffee %s 4. python book %s 5. bicyle %s 你的工资: %s ---------------------------- '''%(price[0],price[1],price[2],price[3],price[4],salary) print(msg) good=input("输入你要购买商品的序号:") if good=="1": if(salary-price[0]>=0): print("已加入:",list[0],"到你的购物车, 当前余额:",salary - price[0],) salary=salary - price[0] list2.append(list[0]) price2.append(price[0]) flag=input("退出请按:(Q/q):") else: print("余额不足:",salary-price[0]) elif good=="2": if (salary - price[1] >= 0): print("已加入:", list[1], "到你的购物车, 当前余额:", salary - price[1], ) list2.append(list[1]) price2.append(price[1]) salary = salary - price[1] flag = input("退出请按:(Q/q):") else: print("余额不足:", salary - price[1]) elif good=="3": if (salary - price[2] >= 0): print("已加入:", list[2], "到你的购物车, 当前余额:", salary - price[2], ) list2.append(list[2]) price2.append(price[2]) salary = salary - price[2] flag = input("退出请按:(Q/q):") else: print("余额不足:", salary - price[2]) elif good=="4": if (salary - price[3] >= 0): print("已加入:", list[3], "到你的购物车, 当前余额:", salary - price[3], ) list2.append(list[3]) price2.append(price[3]) salary = salary - price[3] flag = input("退出请按:(Q/q):") else: print("余额不足:", salary - price[3]) elif good=="5": if (salary - price[4] >= 0): print("已加入:", list[4], "到你的购物车, 当前余额:", salary - price[4], ) list2.append(list[4]) price2.append(price[4]) salary = salary - price[4] flag = input("退出请按:(Q/q):") else: print("余额不足:", salary - price[4]) else: print("输入错误!!!请输入1-5之间") if(flag=="q" or "Q"): print("你已成功退出,以下是你购买的商品:") for i in range(len(list2)): print(list2[i]," ",price2[i]) print("余额:",salary)
Python01小购物车作业
最新推荐文章于 2022-11-23 13:29:29 发布