python 购物车菜单

 用Python写购物车菜单

shop_list=[('手机',5000),('电脑',4000),('咖啡',50),('耳机',150),('笔记本',10)]
myshop_list=[]
salary=input('请输入您的存钱:')

if salary.isdigit():
    salary=int(salary)
    
    for index,items in enumerate(shop_list):
        print(index,items)
        
    while True:
        shop_choice=input('请输入您的要购买的商品:')
    
        if shop_choice.isdigit():
            shop_choice=int(shop_choice)
            
            if 0<=shop_choice<len(shop_list):
                if shop_list[shop_choice][1]<int(salary):
                    myshop_list.append(shop_list[shop_choice])
                    salary-=shop_list[shop_choice][1]
                    print('您购买了{},花费{}元钱,还剩余{}元钱'.format(shop_list[shop_choice][0],shop_list[shop_choice][1],salary))
                    
                else:
                    print('您的余额不足购买{},请重新选择!'.format(shop_list[shop_choice][0]),end="")       

            else:
                print('您的输入有误,',end="")
                
        elif shop_choice=='q':
            print('您已退出系统...')
            print('----您已购买的商品----')
            
            for i in myshop_list:
                print(i)
                
            print('----您的剩余存款为:{}元----'.format(salary))
            exit()
            
        else:
            print('您的输入有误,',end="")
            
elif salary=='q':
    print('您已退出系统...')
    exit()
    
else:
    print('您的输入有误,请从新输入您的存钱:',end="")
    salary=input()



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值