最近alex买了个Tesla Model S,通过转账的形式,并且支付了5%的手续费,tesla价格为95万。账户文件为json,请用程序实现该提现行为。

目录结构如下

├── account
│ └── alex.json
│ └── tesla_company.json
├── bin
│ └── start.py
└── core
└── withdraw.py
当执行start.py时,出现交互窗口

———- ICBC Bank ————-

  1. 账户信息
  2. 提现
    选择1 账户信息 显示alex的当前账户余额和信用额度。

选择2 提现 提现金额应小于等于信用额度,利息为5%,提现金额为用户自定义。

体现代码的实现要写在withdraw.py里

在start.py代码如下

import os
import sys

base_dir = os.path.abspath(os.path.dirname(os.path.dirname(file)))
sys.path.append(base_dir)

from core import withdraw
print(
'ICBC Bank'.center( 30,'-'),'\n'
'1.账户信息''\n'
'2.取现'
)
alex_money = {'user':'alex',}
def choice(num):
if num == '1':
f = open('../account/alex.json','r')
print (type(f.read()))
elif num == '2':
wi_money = input('取现金额').strip()
withdraw.withdraw(wi_money)

choice1 = input('选择服务:')
choice(choice1)

在withdraw代码如下

def withdraw(much):
with open('../account/alex.json','r') as f:
balance = int(float(f.read()))
if balance >= int(much):
with open('../account/alex.json','w') as f:
deduct = balance - int(much)*(1+0.05)
f.write(str(deduct))
elif balance < int(much):
print('余额不足')

posted on   fengxiongmiao  阅读(345)  评论(0编辑  收藏  举报

编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示