标签:balance blog 输入 结算 one 商品 tin [1] logs
goods = ["iphone6s","mac_book","coffee","python_book","bicyle"] price = [5800,9000,32,80,1500] salary = 5000 show_str = """ ____________您的会员卡还有余额 %d元____________ 1. %s %d元 2. %s %d元 3. %s %d元 4. %s %d元 5. %s %d元 _____________请输入您想购买的商品的编号 如:5 结算请输入quit___________ """%(salary,goods[0],price[0],goods[1],price[1],goods[2],price[2],goods[3],price[3],goods[4],price[4]) print(show_str) #小票记录 show_info = [] while True: input_number = input(">>>:") #只能输入正确的商品编号 if input_number.isdigit() and 6 > int(input_number) > 0 : input_number = int(input_number) balance = salary - price[input_number - 1] if(balance < 0): print("您如果购买此商品,您的余额将会是,%d,所以加入购物车失败,请重新选择您消费水平内的商品"%(balance)) else: salary = balance print("已加入%s到您的购物车,当前余额%d"%(goods[input_number-1],salary)) show_info.append("%s---%d"%(goods[input_number-1],price[input_number - 1])) #结算 elif input_number == "quit": if(salary == 5000): print("您可以直接走啊,您还没买什么东西结算个p") else: print("您已购买如下商品") print(show_info) print("您的余额为:%d"%(salary)) exit() #乱输入排除 else: print("请输入正确的商品编号") continue
标签:balance blog 输入 结算 one 商品 tin [1] logs
原文地址:http://www.cnblogs.com/Gimaaa/p/6918613.html