Python实现银行账户资金交易管理系统
作者:浅浅~Smile 时间:2023-09-27 21:37:50
用类和对象实现一个银行账户的资金交易管理, 包括存款、取款和打印交易详情, 交易详情中包含每次交易的时间、存款或者取款的金额、每次交易后的余额。
如:
下面按照要求定义一个账户 Account 类。账户 Account 类的属性:
1. 当前账户金额 money
2. 当前账户交易日志 account_logs
账户 Account 类的方法:
1. 存钱 deposit()无返回值
2. 取钱 withdrawl()无返回值
3. 打印交易详情 transaction_log()无返回值
案例代码如下:
#coding: utf-8
import time
import prettytable as pt
money = 0
acount_logs = []
class Account:
def __init__(self):
global money
self.money = money
self.acount_logs = acount_logs
def deposit(self):
amount = float(input('存入金额:'))
self.money += amount
self.write_log(amount,'转入')
def withdrawl(self):
amount = float(input('取出金额:'))
if amount > self.money:
print('余额不足')
else:
self.money -= amount
self.write_log(amount,'取出')
def transaction_log(self):
tb = pt.PrettyTable()
tb.field_names = ["交易日期","摘要","金额","币种","余额"]
for info in self.acount_logs:
if info[1] =='转入':
amount = '+{}'.format(info[2])
else:
amount = '-{}'.format(info[2])
tb.add_row([info[0],info[1],amount,'人民币',info[3]])
print(tb)
def write_log(self,amout,handle):
create_time = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
data =[create_time,handle,amout,self.money]
self.acount_logs.append(data)
def show_menu():
""" 显示菜单栏 """
menu = """
====================银行账户资金交易管理====================
0: 退出
1:存款
2: 取款
3: 打印交易详情
===========================================================
"""
print(menu)
if __name__ == '__main__':
show_menu()
account = Account()
while True:
choice = int(input("请输入您的选择: "))
if choice == 0:
exit(0)
print("退出系统")
elif choice == 1:
flag = True
while flag:
account.deposit()
flag = True if input("是否继续存款(Y|N): ").lower()== 'y' else False
elif choice == 2:
flag = True
while flag:
account.withdrawl()
flag = True if input("是否继续取款(Y|N): ").lower()== 'y' else False
elif choice == 3:
account.transaction_log()
else:
print("请选择正确的编号")
测试结果如下:
====================银行账户资金交易管理====================
0: 退出
1:存款
2: 取款
3: 打印交易详情
===========================================================
请输入您的选择: 1
存入金额:300
是否继续存款(Y|N): N
请输入您的选择: 2
取出金额:300
是否继续取款(Y|N): Y
取出金额:100
余额不足
是否继续取款(Y|N): N
请输入您的选择: 3
+---------------------+------+--------+--------+-------+
| 交易日期 | 摘要 | 金额 | 币种 | 余额 |
+---------------------+------+--------+--------+-------+
| 2020-01-02 19:53:54 | 转入 | +300.0 | 人民币 | 300.0 |
+---------------------+------+--------+--------+-------+
+---------------------+------+--------+--------+-------+
| 交易日期 | 摘要 | 金额 | 币种 | 余额 |
+---------------------+------+--------+--------+-------+
| 2020-01-02 19:53:54 | 转入 | +300.0 | 人民币 | 300.0 |
| 2020-01-02 19:54:02 | 取出 | -300.0 | 人民币 | 0.0 |
+---------------------+------+--------+--------+-------+
请输入您的选择: 5
请选择正确的编号
请输入您的选择: 0
Process finished with exit code 0
如果可以每次存入和取出钱之后都有余额提示就更友好了!
总结
以上所述是小编给大家介绍的Python实现银行账户资金交易管理系统网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
来源:https://blog.csdn.net/daidadeguaiguai/article/details/103808957
标签:python,银行,账户,资金,交易
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Go/C语言LeetCode题解997找到小镇法官
2024-05-21 10:18:54
lnmp重置mysql数据库root密码的两种方法
2024-01-25 13:55:51
Python中函数及默认参数的定义与调用操作实例分析
2022-01-15 05:16:31
![](https://img.aspxhome.com/file/2023/2/90302_0s.jpg)
使用SQL Server时最容易忽略的21个问题
2009-01-13 13:59:00
python字符串判断密码强弱
2021-05-09 04:20:04
Pandas中的 transform()结合 groupby()用法示例详解
2023-01-26 10:00:09
![](https://img.aspxhome.com/file/2023/5/85135_0s.png)
详解Go语言如何实现二叉树遍历
2024-04-23 09:44:10
![](https://img.aspxhome.com/file/2023/5/134335_0s.png)
Python操作Word批量生成合同的实现示例
2023-06-17 09:59:14
Python OpenCV实现姿态识别的详细代码
2023-05-27 23:42:31
![](https://img.aspxhome.com/file/2023/9/78719_0s.jpg)
Asp中Scripting.TextStream 对象介绍
2007-11-02 12:19:00
如何使用Maxwell实时同步mysql数据
2024-01-18 01:43:23
![](https://img.aspxhome.com/file/2023/3/114033_0s.png)
XPath 1.0 学习笔记
2009-02-25 12:19:00
MSSQL差异备份取系统权限的相关软件下载
2024-01-21 16:08:46
Pytest接口自动化测试框架搭建模板
2022-01-29 02:26:44
Dreamweaver打造多彩文字链接
2007-11-11 18:59:00
![](https://img.aspxhome.com/file/uploadpic/20072/200723113810748.gif)
详解Golang语言HTTP客户端实践
2023-09-17 13:52:07
python moviepy 的用法入门篇
2022-09-03 11:41:16
![](https://img.aspxhome.com/file/2023/5/131325_0s.png)
Python Selenium操作Cookie的实例方法
2022-10-22 10:21:34
Python中关于property使用的小技巧
2021-01-25 04:35:44
基于Python的ModbusTCP客户端实现详解
2022-02-03 10:54:25
![](https://img.aspxhome.com/file/2023/1/115721_0s.jpg)