SHOPING 购物(学了老男孩视频写的)
#!/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 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
????????????????#輸入工資,不是數值異常處理
??????????????? #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 you didn't buy this is you 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 退出判斷
? ? ? ? ? ? ? ? ? ? ? ?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,"you have ",gongz,"\033[0m"
??????????????? else:
??????????????????????? print "\033[31;1mdon't hava this wp,you have",gongz,"\033[0m"
??????????????????????? continue
轉載于:https://blog.51cto.com/bluechen/1695956
總結
以上是生活随笔為你收集整理的SHOPING 购物(学了老男孩视频写的)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: msys2编译php,MSYS2初体验
- 下一篇: js实现点击div以外区域,隐藏div区