码迷,mamicode.com
首页 > 编程语言 > 详细

PYTHON 购物车程序

时间:2016-12-24 16:24:54      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:use   for   choice   pytho   ping   app   lan   无法   opp   

product_list = [
    (iphone,50000),
    (Mac Pro,9900),
    (Bike,8000),
    (Watch,160000),
    (Coffee,600),
    (‘lqgyc,1200)

]
shopping_list = []
salary = input("请输入工资:")
if salary.isdigit():  # isdigit() 方法检测字符串是否只由数字组成
    salary = int(salary)
    while True:
        for index,item in enumerate(product_list):
            print(index,item)
        user_choice = input("请选择商品>>>")
        if user_choice.isdigit():
            user_choice = int(user_choice)

            if user_choice < len(product_list) and user_choice >= 0:
                p_item = product_list[user_choice]
                if p_item[1] <= salary:
                    shopping_list.append(p_item)
                    salary -= p_item[1]
                    print("Added %s into shopping cart,your current balar:",salary)

                else:
                    print("你的余额只剩[%s]啦,无法购买"% salary)
            else:
                print("product code [%s] is not exist !" % user_choice)
        elif user_choice == q:
            print(---商品列表!---)
            for p in shopping_list:
                print(p)
            print("your current balance:", salary)
            exit()
        else:
            print("请输入商品序列号!")

 

PYTHON 购物车程序

标签:use   for   choice   pytho   ping   app   lan   无法   opp   

原文地址:http://www.cnblogs.com/zgyc/p/6217244.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!