zoukankan      html  css  js  c++  java
  • 购物车(注册、登录、购物、购物车、结帐)

    '''
    购物车(注册、登录、购物、购物车、结帐)
    '''

    shopping_car_dict=dict()
    money=[0]
    def input_username_pwd():
        username=input('username:')
        pwd=input('pwd:')
        return username,pwd
    def goods_get():
        with open('goods.txt','r',encoding='utf8')as fr:
            fr1=fr.read()
            fr2=eval(fr1)
            return fr2
    fr2=goods_get()
    
    
    def register():
        print('欢迎来到注册功能:')
        username,pwd=input_username_pwd()
        with open('user_info.txt','a',encoding='utf8')as fa:
            fa.write(f'{username}:{pwd}|')
    def login():
        print('欢迎来到登录功能:')
        username,pwd=input_username_pwd()
        username1=f'{username}:{pwd}'
        with open('user_info.txt', 'r', encoding='utf8')as fr:
            fr2=fr.read()
            username2=fr2.split('|')
        if username1 in username2:
            print('登录成功')
        else:
            print('密码不对')
    
    
    def shopping():
        print('欢迎来到购物天堂:')
        while True:
            for ind,goods in enumerate(fr2):
                print(f'商品编号{ind}',goods)
            choice=input('请选择商品编号,退出请按q:')
            if choice=='q':
                break
            choice=int(choice)
            goods=fr2[choice]
            print(f'购买商品{goods}成功,
    ')
            goods_name=goods[0]
            if goods_name in shopping_car_dict:
                shopping_car_dict[goods_name]+=1
            else:
                shopping_car_dict[goods_name]=1
            money[0]+=goods[1]
        print(f'你购买的商品是{shopping_car_dict},总价是{money[0]}')
    
    
    
    
    def shopping_car():
        print('欢迎来到购物车功能:')
        while True:
            print(f'你购买的商品是{shopping_car_dict},总价是{money[0]}')
            choice=input('请输入你要删除的商品编号,退出请按q:')
            if choice=='q':
                break
            shopping_car_dict[choice]-=1
            for goods in fr2:
                for choice in goods:
                    money[0]-=goods[1]
    def pay():
        print('欢迎来到付款中心')
        print(f'你购买的商品是{shopping_car_dict},总价是{money[0]}')
        choice=input('确认付款请按Y或y,清空购物车请按N或n:')
        if choice=='Y'or choice=='y':
            print(f'你已支付{money[0]}元,购买的商品是{shopping_car_dict}')
        elif choice=='N'or choice=='n':
            shopping_car_dict.clear()
            money[0]=0
            print('购物车已清空')
        else:
            print('输入不合法')
    
    
    
    
    
    
    
    
    
    
    
    
    func_msg='''
    1:注册
    2:登录
    3:购物
    4:购物车
    5:消费
    '''
    func_choice={
        '1':register,
        '2':login,
        '3':shopping,
        '4':shopping_car,
        '5':pay,
    }
    while True:
        print(func_msg)
        lc=input('请输入你想要选择的功能,退出请按q:')
        if lc=='q':
            break
        else:
            func_choice[lc]()
    
  • 相关阅读:
    Team饭来了团队作业3需求改进与系统设计
    2016012006崔啸寒 散列函数的应用及其安全性
    结对项目之四则运算
    《构建之法》第四章,第十七章所感
    2016012006小学四则运算练习软件项目报告
    读《构建之法》之一,二,十六章有感
    追梦软件路,愿不忘初心
    信息安全作业5 有关散列函数安全性的知识扩展
    结对作业:四则运算网页版
    Week4-作业1:阅读笔记与思考
  • 原文地址:https://www.cnblogs.com/jinhongquan/p/11354821.html
Copyright © 2011-2022 走看看