• Python 小案例实战 —— 简易银行存取款查询系统


    Python 小案例实战 —— 简易银行存取款查询系统

    涉及知识点

    • 包的调用
    • 字典、列表的混合运用
    • 列表元素索引、追加
    • 基本的循环与分支结构

    源码

    import sys
    import time
    
    bank = {
        'users':['Tom','Jack'],
        'pwd': ['1701', '1702'],
        'money':[1000,2000],
        'history':[[],[]]
    }
    
    while True:
        user_now_name = str(input("欢迎使用本系统!请输入您的用户名:
    "))
        if user_now_name in bank['users']:
            user_index = bank['users'].index(user_now_name)
            # print('尊敬的', user_now_name, '您好!')
            while True:
                user_now_pwd = str(input("请输入您的密码:
    "))
                if user_now_pwd == bank['pwd'][user_index]:
                    print('登录成功!')
                    isLogin = True
                    bank['history'][user_index].append(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + '         登陆系统')
                    break
                else:
                    print('密码错误,请重试!
    ')
            break
        else:
            print('抱歉,不存在该用户!
    ')
    
    
    while isLogin:
         print('
    请选择您要办理的业务:1.取款,2.存款,3.查询,4.退卡')
         service_num = int(input())
         if service_num == 1:
            money_out = int(input('请输入取款金额:'))
            if money_out > 0 and money_out < int(bank['money'][user_index]):
                bank['money'][user_index]  = int(bank['money'][user_index]) - money_out
                print('当前剩余存款:', bank['money'][user_index])
                bank['history'][user_index].append(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + '         取款' + str(money_out))
            else:
                print('当前余额不足!!')
         elif service_num == 2:
            money_in = int(input('请输入存款金额:'))
            if money_in < 0:
                print('存款金额必须大于0')
            else:
                bank['money'][user_index]  = int(bank['money'][user_index]) + money_in
                print('当前剩余存款:', bank['money'][user_index])
                bank['history'][user_index].append(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + '         存款' + str(money_in))
         elif service_num == 3:
             for record in bank['history'][user_index]:
                print(record)
         elif service_num == 4:
             bank['history'][user_index].append(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + '         退出系统')
             break
    

    运行测试结果

    欢迎使用本系统!请输入您的用户名:
    GShang
    抱歉,不存在该用户!
    
    欢迎使用本系统!请输入您的用户名:
    Tom
    请输入您的密码:
    1702
    密码错误,请重试!
    
    请输入您的密码:
    1701
    登录成功!
    
    请选择您要办理的业务:1.取款,2.存款,3.查询,4.退卡
    1
    请输入取款金额:1200
    当前余额不足!!
    
    请选择您要办理的业务:1.取款,2.存款,3.查询,4.退卡
    1
    请输入取款金额:200
    当前剩余存款: 800
    
    请选择您要办理的业务:1.取款,2.存款,3.查询,4.退卡
    2
    请输入存款金额:800
    当前剩余存款: 1600
    
    请选择您要办理的业务:1.取款,2.存款,3.查询,4.退卡
    1
    请输入取款金额:1700
    当前余额不足!!
    
    请选择您要办理的业务:1.取款,2.存款,3.查询,4.退卡
    1
    请输入取款金额:100
    当前剩余存款: 1500
    
    请选择您要办理的业务:1.取款,2.存款,3.查询,4.退卡
    3
    2019-12-20 10:40:47         登陆系统
    2019-12-20 10:40:57         取款200
    2019-12-20 10:41:01         存款800
    2019-12-20 10:41:14         取款100
    
    请选择您要办理的业务:1.取款,2.存款,3.查询,4.退卡
    4
    
    Process finished with exit code 0
    
    
  • 相关阅读:
    Invalid character found in method name. HTTP method names must be tokens
    使用idea合并分支
    jenkins企业级实战
    Custom runner class Runner should have a public constructor with signature R
    java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.([Ljava
    eclipse启动A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be available in order
    windows配置jdk环境变量
    无法上传空目录到git仓库
    VirtualBox配置Centos网络和域名解析
    052(二十)
  • 原文地址:https://www.cnblogs.com/gshang/p/12071838.html
Copyright © 2020-2023  润新知