python 购物车程序_Python 之 购物车程序(列表使用场景)

要求:

1、程序运行时,让用户输入工资大小。

2、列出当所有产品列表清单。

3、让用户输入需要购买的产品编号。

4、结束程序时,打印购买明细与剩下余额。

#Author Kang

shopping_list = [('Iphone',5000),('MacBook',9000),('Huwei P20',9999)]

shopping_car = []

salary = int(input('请输入你的工资:'))

while True:

for index,item in enumerate(shopping_list):

print(index,item)

user_change = input('请输入你要购买的产品编号:')

if user_change.isdigit():

user_change=int(user_change)

if user_change >= 0 and user_change < len(shopping_list) and salary >= shopping_list[user_change][1]:

shopping_car.append(shopping_list[user_change])

salary -=shopping_list[user_change][1]

elif salary <= shopping_list[user_change][1] :

print('你的余额已经不足!!!')

else:

print('你输入的编号有误,请重新输入!!!!!')

elif user_change == 'q':

print('--------已购买的产品-------')

print(shopping_car)

print('剩下的余额为>>>:',salary)

exit()

else:

print("输入有误,请重新输入")

标签:salary,shopping,Python,list,列表,user,输入,购物车,change

来源: http://blog.51cto.com/12965094/2343990

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值