zoukankan      html  css  js  c++  java
  • day04_final

    作业需求:

    模拟实现一个ATM + 购物商城程序

    1. 额度 15000或自定义
    2. 实现购物商城,买东西加入 购物车,调用信用卡接口结账
    3. 可以提现,手续费5%
    4. 每月22号出账单,每月10号为还款日,过期未还,按欠款总额 万分之5 每日计息
    5. 支持多账户登录
    6. 支持账户间转账
    7. 记录每月日常消费流水
    8. 提供还款接口
    9. ATM记录操作日志 
    10. 提供管理接口,包括添加账户、用户额度,冻结账户等。。。
    11. 用户认证用装饰器

    1、额度15000或自定义功能。

    # Author: ray.zhang
    
    import sys
    
    while True:
        user = str(input("33[1;32;40mPlease input your name:33[0m"))
        f = open('user_list', 'r+')
        for line in f.readlines():
            n = str(line.split()[0])
            p = str(line.split()[1])
            if user == n:
                while True:
                    password = str(input("33[1;32;40mPlease input your password:33[0m"))
                    if password != p:
                        print
                        "33[1;31;40mThe password is incorrect33[0m"
                        continue
                    else:
                        print
                        "33[1;32;40myes let you in.33[0m"
                        global money
                        money_total = 15000
                        print("33[1;33;40mYou total money is: 33[0m", money_total)
                        exit()
            else:
                print
                "33[1;31;40mThe user is not vaild, please re-input:33[0m"
                continue
    

    2、支持多账户登录

    # Author: ray.zhang
    
    dict = {
        'user1':{'pass':123,'count':0},
        'user2':{'pass':456,'count':0},
        'user3':{'pass':789,'count':0}
    }
    
    
    name = input ("plz input your name: ")
    print (dict[name]['pass'])
    
    if name not in dict:
        print ("Sorry,you input error.")
        exit()
    elif name in dict :
        print ("Ok,you input success.")
    
        while dict[name]['count'] < 3:
    
            pas = int(input("plz input your passwd: "))
    
            if pas == dict[name]['pass']:
                print ("Congratulation to you.")
                dict[name]['count'] = 3
            else:
                dict[name]['count'] += 1
    

    3、实现用户认证装饰器

    # Author: ray.zhang
    
    import time
    
    user_dict={'user':None}
    def auth(func):
        def wrapper():
            print(user_dict['user'])
            #user = user_dict['user']
            #print(user_dict['user'])
            if user_dict['user']:
                starttime = time.time()
                func()
                stoptime = time.time()
                print("Run time is %s" % (stoptime - starttime))
            if not user_dict['user']:
                user = input("plz input your user:").strip()
                passwd = int(input("plz input your passwd:").strip())
                with open('info','r',encoding='utf-8') as f:
                    date=eval(f.read())
                    starttime = time.time()
                    if user in date and passwd == date[user]:
                    # if user == "erav" and passwd == 123:
                        print("you input success...")
                        func()
                        stoptime = time.time()
                        print("Run time is %s" %(stoptime - starttime))
                        user_dict['user'] = user
                    else:
                        print("you input error...")
        return wrapper
    
    @auth                   #这个就相当于 timmer=auth(timmer)
    def timmer():
        time.sleep(2)
        print("welcome to shopping")
    
    
    
    timmer()
    

      

  • 相关阅读:
    读《大道至简》第6章有感
    Java作业05(动手动脑)
    读《大道至简》第五章有感
    java作业04(动手动脑)
    域名与主机名
    STL 迭代器学习
    数组与链表增删改查效率比较
    智能指针多线程安全问题
    快速乘 学习
    关于TCP三个冗余ACK启动快速重传
  • 原文地址:https://www.cnblogs.com/zhangray/p/7248302.html
Copyright © 2011-2022 走看看