python 购物车菜单

xiaoxiao2021-02-28  60

 用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()

转载请注明原文地址: https://www.6miu.com/read-43655.html

最新回复(0)