• 编写购物车,初级版。。。


    product_list=[
        ('iphone',5000),
        ('mac',8000),
        ('telsa',9000),
        ('mac pro',4300),
        ('iwatch',8434),
    ]
    shopping_list=[]
    salary=input('pls input your salary:')
    if salary.isdigit():
        salary=int(salary)
        while True:
            for index,item in enumerate(product_list):
                print(index,item)
            user_choice=input('请选择要买的商品:')
            # if user_choice<product_list.index(item)
            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 cat,you salary %s' %(p_item,salary))
                    else:
                        print('你买不起该商品,余额不足')
                else:
                    print('你输入的商品%s不存在,请重新输入。。。' %user_choice)
    
            elif user_choice=='q':
    
                print('shopping list')
                for p in shopping_list:
                    print(p)
                print('你现在的余额为%s'%salary)
                exit()
            else:
                print('invalid option')
    

      

  • 相关阅读:
    CTF工具使用
    关于CTF的Misc
    stegsolve使用方法
    CTF练习平台
    关于命令执行漏洞深入学习
    redis未授权访问漏洞复现
    Vulnhub实战靶场:DC-2
    Vulnhub实战靶场:DC-1
    NISP一级真题、NISP一级题库
    封神台靶场:萌新也能找CMS突破
  • 原文地址:https://www.cnblogs.com/zhangzihong/p/6100762.html
Copyright © 2020-2023  润新知