首页 > 其他 > 详细

老男孩培训练习购买商品

时间:2017-12-23 20:12:12      阅读:207      评论:0      收藏:0      [点我收藏+]
#!/usr/bin/env python #-*-coding=utf-8 -*- #AUTHOR:duwentao product_list = [     ('Iphone',5000),     ('book',10),     ('watch',10600),     ('bike',800), ] shopping_list=[] #判断工资是否为数字 salary = input("请输入你的工资:") if salary.isdigit():     salary = int(salary) while True:     for item in product_list:         print (product_list.index(item),item)     user_choice = input('请输入你要购买的商品号:')     if user_choice.isdigit():         user_choice = int(user_choice)         if user_choice >= 0 and user_choice < len(product_list):             p_item = product_list[user_choice]             if p_item[1] > salary:                 print('余额不足')             else:                 shopping_list.append(item)                 salary  -=  p_item[1]                 print('你已经购买了%s,您的余额为%s' %(item,salary))         else:             print('你购买的商品不存在')     elif user_choice == 'q':         print ('----shopping list----')         for p in shopping_list:             print(p)         print('你的余额为',salary)         exit()     else:         print ("输入有误,请重新编号")         print ("正在退出")         exit()


老男孩培训练习购买商品

原文:http://blog.51cto.com/tdcqvip/2053893

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!