Alex recently bought a Tesla Model S, in the form of transfers, and pay a 5% commission, tesla price of 95 million. Account file json, please use the program the dash for cash.

Directory structure is as follows

The Account ├──
│ └── alex.json
│ └── tesla_company.json
├── bin
│ └── start.py
└── Core
└── withdraw.py
interactive window when performing start.py, appear

———- ICBC Bank ————-

  1. account information
  2. Withdraw
    Option 1 account information shows the current account balance and credit limit of alex.

Select 2 to cash withdrawals should be less than the amount equal to the credit limit, interest rate of 5%, cash amounted to mention user-defined.

It reflects the realization in code to write in withdraw.py

In the following code 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 ( 'service selection:')
Choice (Choice1)

In the following code 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('余额不足')

Guess you like

Origin www.cnblogs.com/fxm12138/p/12120950.html