第五天,复习第四天内容,购物车小程序作业.元组

#author: zoe
#date: 2019/5/31
salary = int(input(“欢迎光临本店,请输入您的预算:”))
print(‘1. iphone6s’,’\t’,‘5800’,’\n’
‘2. mac book’,’\t’,‘9000’,’\n’
‘3. coffee’,’\t\t’,‘32’,’\n’
‘4. python book’,’’,‘80’,’\n’
‘5. bicycle’,’\t\t’,‘1500’,end=’\n’)
goods = [‘0’,‘ipone6s’,‘mac book’,‘coffee’,‘python book’,‘bicycle’]
price = [‘0’,‘5800’,‘9000’,‘32’,‘80’,‘1500’]
shopping_cart = list()
rest_cash = int(salary)
quit_flag = True
while quit_flag :
choice = input(‘请选择商品或者按q退出:’)
if choice == ‘q’:
quit_flag = False
continue
if rest_cash - int(price[int(choice)]) < 0:
print(‘余额不足,请重新选择.还需要’,-(rest_cash - int(price[int(choice)])))
continue
rest_cash -= int(price[int(choice)])
shopping_cart.append(goods[int(choice)])
print(goods[int(choice)],‘已加入您的购物车,当前余额:’,rest_cash)
else :
print(‘欢迎下次光临,您已购买:’,shopping_cart,‘一共花费:’,salary - rest_cash)

元组与列表类似
a=(1,2,3,4,5)
可以切片取值,不能修改元组里面的内容.

购物车程序可以继续优化.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值