1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 # Author:Er fei 4 input_wage=input("请输入工资:") 5 input_wage=input_wage.strip() 6 if input_wage.isdigit(): 7 input_wage=int(input_wage) 8 goods_list={"苹果4s":800,"苹果6s":5000,"苹果7":7000,"oppor9":5999} 9 print("欢迎来到网络商城".center(50,"*")) 10 print(goods_list) 11 buy_list={} 12 while True: 13 already_bought=input("苹果4s:1,6s:2,7:3,oppor9:4请输入要购买的商品:") 14 if already_bought=="1": 15 goods=goods_list["苹果4s"] 16 if goods_list["苹果4s"]<input_wage: 17 input_wage=input_wage-goods_list["苹果4s"] 18 print(input_wage) 19 buy_list["苹果4s"]=800 20 print(buy_list) 21 else: 22 print("余额不足请充值或更换商品后重试!") 23 24 25 elif already_bought=="2": 26 goods = goods_list["苹果6s"] 27 if goods_list["苹果6s"] < input_wage: 28 input_wage = input_wage - goods_list["苹果6s"] 29 print(input_wage) 30 buy_list["苹果6s"] = 5000 31 print(buy_list) 32 else: 33 print("余额不足请充值或更换商品后重试!") 34 elif already_bought=="3": 35 goods = goods_list["苹果7"] 36 if goods_list["苹果7"] < input_wage: 37 input_wage = input_wage - goods_list["苹果7"] 38 print(input_wage) 39 buy_list["苹果7"] = 7000 40 print(buy_list) 41 else: 42 print("余额不足请充值或更换商品后重试!") 43 elif already_bought=="4": 44 goods = goods_list["oppor9"] 45 if goods_list["苹果4s"] < input_wage: 46 input_wage = input_wage - goods_list["oppor9"] 47 print(input_wage) 48 buy_list["oppor9"] = 5999 49 print(buy_list) 50 else: 51 print("余额不足请充值或更换商品后重试!") 52 else: 53 print("输入不合法请重新输入工资!!!")