• python_30_购物车复习


    prodcut_list=[
        ('Iphone', 5800),
        ('Mac Pro', 9800),
        ('Bike', 800),
        ('Watch', 10600),
        ('Coffee', 31),
        ('Python Book', 49)
    ]
    shopping_list=[]
    salary=int(input('Input your salary:'))
    while True:
        for index,item in enumerate(prodcut_list):
            print(index,item)
        choice=input('>>>:选择要买嘛?>>>:')
        if choice.isdigit():
            choice=int(choice)
            if choice<len(prodcut_list) and choice>=0:
                p_item=prodcut_list[choice]
                if p_item[1]<salary:
                    salary-=p_item[1]
                    shopping_list.append(p_item)
                    print("Added %s into your shopping cart,your current balance is 33[32;1m%d33[0m"%(p_item,salary))
                else:
                    print("33[42;1m你的余额只有%d,还买个球呀33[0m"%salary)
            else:
                print("商品[%s]不存在"%choice)
        elif choice=='q':
            print('--------shoppinglist--------')
            for p in shopping_list:
                print(p)
            print("你的余额:",salary)
            exit()
        else:
            print('invalide option')
    

      

  • 相关阅读:
    XML 编码
    XML CDATA
    XML 命名空间
    XML 解析器
    XML XMLHttpRequest 对象
    XML 和CSS
    XML 验证
    XML 属性
    XML 元素
    XML 语法规则
  • 原文地址:https://www.cnblogs.com/tianqizhi/p/8203501.html
Copyright © 2020-2023  润新知