标签:list while book app lease [1] 交易 需求 this
购物车小程序
需求描述如下:
1.提示用户输入薪水
2.用户输入薪水后,打印商品编号、内容及价格
3.提醒用户输入商品代码,若余额大于等于商品价格,可购买;若小于,提示用户余额不足
4.用户输入q ,退出交易,打印用户购买的商品和余额
#-*-coding:utf-8 -*- goods_list=[(‘Iphone‘,5800),(‘Mac Pro‘,12000),(‘Coffee‘,31),(‘Book‘,81),(‘Bike‘,8000)] goods_bought=[] salary=input("please input your salary:") if salary.isdigit(): salary=int(salary) balance=salary while True: print("This is our goods list:") for index,item in (enumerate(goods_list)): print(index,item) goods_number=(input("please input goods number you want:")) if goods_number.isdigit(): goods_number=int(goods_number) if goods_number>=0 and goods_number<(len(goods_list)): if goods_list[goods_number][1]<=balance: goods_bought.append(goods_list[goods_number]) balance=balance-goods_list[goods_number][1]%(goods_list[goods_number].balance) else: print("Your balance %s is not enough!"%balance) else: print("The goods number %s is not exist!"%goods_number) elif goods_number==‘q‘: print("Your goods are:") for item in goods_bought: print(item) print("your balance is:%s"%balance) goods_bought.clear() exit() else: print("Your input is wrong!") else: print("your salary is wrong:")
标签:list while book app lease [1] 交易 需求 this
原文地址:https://www.cnblogs.com/zijue/p/9797047.html