码迷,mamicode.com
首页 > 其他好文 > 详细

购物程序

时间:2017-07-01 00:12:58      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:输入   use   pen   python   错误   user   余额   pre   list   

shoplist = []
product_list = [
    (‘computer‘,5000),
    (‘apple‘,50),
    (‘book‘,42),
    (‘iphone‘,6800)
]
salary = input("输入您的工资:")
if salary.isdigit():
    salary = int(salary)
while True:
    for index,iteam in enumerate(product_list):
        print(index,iteam)
    user_choice = input("你想买什么?")
    if  user_choice.isdigit():
        user_choice = int(user_choice)
        if user_choice < len(product_list) and user_choice >=0:
            p_iteam = product_list[user_choice]
            if p_iteam[1] <= salary:
                shoplist.append(p_iteam)
                salary = salary - p_iteam[1]
                print("你购买了%s,您的余额为;%s" %(p_iteam,salary))
            else:
                print("你都没钱了,买不起啊!")
        else:
            print("没有您需要的产品!")
    elif user_choice == ‘q‘:
        print("----------购物清单----------")
        for p in shoplist:
            print(p)
        print("你的余额:", salary)
        exit()
    else:
        print("错误的类型")

 

购物程序

标签:输入   use   pen   python   错误   user   余额   pre   list   

原文地址:http://www.cnblogs.com/csjgs/p/7100927.html

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