#!/usr/bin/python
Import syslog
Import Sys
this_year=2015
product=[' Apple ', ' coffee ', ' pc ', ' Rebot ', ' clothes ', ' licai '] #创建数组
PRICE=[4999,30,8000,100000,1000,500] #创建数组
Qingdan = [] #创建数组
While True:
Try
Gongz=int (raw_input (' \033[33;1mplease input you gz:\033[0m '). Strip ())
Break
#输入工资, not numeric exception handling
#except ValueError:
Except ValueError:
Print "error:you must input a num"
While True:
print ' \033[35;1mplease looking for caidan\033[0m ' #输出你的菜单
For line in product:
#在你的数组中循环
Print "\033[32;1m%s\t%s\033[0m"% (Line,price[product.index (line)])
#输出你的购物清单
If Gongz < min (price): #判断是否购买的起
Print "\033[34;1m didn ' t buy this is buy\033[0m"
Print "\033[34;1m", Qingdan, "\033[0m"
#输出你已经购买的
Sys.exit ()
Else
Goumai = Raw_input (' \033[32;1m you need shopping,please take it\033[0m ')
#选择购买的物品
If goumai== ' exit ':
#exit exit Judgment
Print "\033[35;1m you buy", Qingdan, "\033[0m"
Sys.exit ()
If Goumai in product:
If Gongz < Price[product.index (Goumai)]:
#判断是否购买的了
Print "\033[31;1myou can ' t buy", Goumai, "Youhave", Gongz, "\033[0m"
#输出不能买已经清单
Continue
Else
Qingdan.append (Goumai)
#购买的物品添加到数组中
Gongz = Gongz-price[product.index (Goumai)]
#工资减去物品的价格
Print "\033[35;1m you buy", Qingdan, "We have", Gongz, "\033[0m"
Else
print "\033[31;1mdon ' t hava this wp,you has", Gongz, "\033[0m"
Continue
This article is from the "Once Operations" blog, please be sure to keep this source http://bluechen.blog.51cto.com/8739192/1695956
Shoping shopping (learned the old boy video written)