买东西

#!/usr/bin/env python
gongzi = 5000
import sys
caidan = ‘’’

A:Iphone : 5888
B:Computer: 11000
C:Xiaomi: 2499
D:Mouse : 129
E:TV : 2499
Q:quit

What would you want to buy?
‘’’

panduan = 0
things=[‘A’,‘B’,‘C’,‘D’,‘E’] ##代号
price=[‘5888’,‘11000’,‘2499’,‘129’,‘2499’] ##价格
stuff=[‘Iphone’,‘Computer’,‘Xiaomi’,‘Mouse’,‘TV’] ##物品名称
have=[]
while True:
print caidan ##打印菜单
anser = raw_input(‘you can input “A” or “a”: \n’).upper() ##输入要购买的物品
if anser == “Q”: ##如果选择退出
print “You have bought below stuff:”
print have
sys.exit(‘Good Bye!’)
if anser not in things: ##如果选择不存在的物品
print “you’s input is wrong,please input ‘a’ or ‘A’!”
continue
for i in things:
if anser == i: ##判断选择的物品对应的价格
a = things.index(anser)
if int(gongzi) >= int(price[a]): ##可以购买时
b = int(gongzi) - int(price[a])
print “OK! You buy success! You have %s yuan now!” %b
have.append(stuff[a]) ##购买成功的物品添加进已拥有列表
print ‘Do you want to buy go on?’
on = raw_input(‘please input no or other:’) ##判断是否需要继续购物
if on == ‘no’:
print “You have bought below stuff:”
print have
sys.exit(“Bye-Bye!”)
gongzi = int(b)
if int(gongzi) < int(price[a]): ##不够支付时
print “Sorry! this things need %s ! you have %s!” %(price[a],gongzi)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值