我正在使用Python3,我为“银行”制定了一个框架,包括存款,取款和付款。当然,银行是高度集中的,我是唯一能够进行这些存款/取款的人。我不是在寻找加密或安全性,但我正在寻找一种方法来增加账户余额的利息并增加债务利息,除了在经济中拥有有限的资金(即我不能无限地将资金存入账户) 。具体而言,我希望每周平衡利息,我希望银行的任何债务都能以利息支付。我在这里不知所措。 这是代码:
main.py:
import s as s
import b as b
import d as d
import l as l
bList2 = b.bList
dList2 = d.dList
sList2 = s.sList
log2 = l.log
index2 = 0
class test:
def __init__(self):
global index2
global bList2
global dList2
global sList2
self.ID = index2
index2 += 1
thing = self.ID in s.sList
if thing == True:
self.balance = bList2[self.ID]
self.debt = dList2[self.ID]
else:
self.balance = 5000
self.debt = 0
bList2.append(self.balance)
dList2.append(self.debt)
thing2 = open("b.py", 'w')
thing2.write("bList = " + str(bList2))
thing2.close()
thing3 = open("d.py", 'w')
thing3.write("dList = " + str(dList2))
thing3.close()
sList2 = s.sList
sList2.append(self.ID)
thing4 = open("s.py", 'w')
thing4.write("sList = " + str(sList2))
thing4.close()
def withdraw(self, amount):
global bList2
global log2
if amount > self.balance or self.balance < 0:
bal3 = (self.balance - amount)
bal2 = ((self.balance - amount) * -1)
thing5 = str(input("Are you sure you would like to withdraw $" + str(amount) + " from your account? You will be $" + str(bal2) + " in debt. (y/n)")).lower()
if thing5 == "y":
thing6 = str(input("Are you sure? (y/n)")).lower()
if thing6 == "y":
self.balance = bal3
bList2[self.ID] = self.balance
thingy8 = open("b.py", 'w')
thingy8.write("bList = " + str(bList2))
thingy8.close()
log2.append("Account ID " + str(self.ID) + " withdrew $" + str(amount) + "and now has a current balance of $" + str(bal3))
thing9 = open("l.py", 'w')
thing9.write("log = " + str(log2))
thing9.close()
else:
bal4 = (self.balance - amount)
thing10 = str(input("Are you sure you would like to withdraw $" + str(amount) + " from your account? You will have $" + str(bal4) + " remaining. (y/n)")).lower()
if thing10 == "y":
bList2[self.ID] = bal4
thing11 = open("b.py", 'w')
thing11.write("bList = " + str(bList2))
thing11.close()
log2.append("Account ID " + str(self.ID) + " withdrew $" + str(amount) + " and now has a current balance of $" + str(bal4))
thing12 = open("l.py", 'w')
thing12.write("log = " + str(log2))
thing12.close()
self.balance = bal4
def deposit(self, amount):
global bList2
global log2
if amount <= 0:
print ("Please provide an amount that is above $0.00")
else:
bal5 = (self.balance + amount)
thing14 = str(input("Are you sure you would like to deposit $" + str(amount) + " in your account? Your current balance is $" + str(self.balance) + " and your deposit will raise it to $" + str(bal5) + " (y/n)")).lower()
if thing14 == "y":
self.balance = bal5
bList2[self.ID] = self.balance
thing15 = open("b.py", 'w')
thing15.write("bList = " + str(bList2))
thing15.close()
log2.append("Account ID " + str(self.ID) + " deposited $" + str(amount) + " and now has a current balance of $" + str(self.balance))
thing16 = open("l.py", 'w')
thing16.write("log = " + str(log2))
thing16.close()
def pay(self, amount, receiver):
global bList2
global log2
thingy2 = receiver.ID in s.sList
if thingy2 == True:
if amount > self.balance or self.balance <= 0:
print ("not enough funds")
elif amount <= 0:
print ("please provide a number that is greater than 0")
else:
thingy3 = (self.balance - amount)
thingy4 = str(input("Are you sure you would like to pay account ID " + str(receiver.ID) + " a sum of $" + str(amount) + "? You will have $" + str(thingy3) + " remaining. (y/n)")).lower()
if thingy4 == "y":
thingy5 = (receiver.balance + amount)
receiver.balance = thingy5
self.balance = thingy3
bList2[receiver.ID] = thingy5
bList2[self.ID] = thingy3
thingy5 = open("b.py", 'w')
thingy5.write("bList = " + str(bList2))
thingy5.close()
log2.append("Account ID " + str(self.ID) + " paid account ID " + str(receiver.ID) + " $" + str(amount) + ". Account ID " + str(self.ID) + " currently has a balance of $" + str(self.balance) + ", and account ID " + str(receiver.ID) + " has a balance of $" + str(receiver.balance))
thingy6 = open("l.py", 'w')
thingy6.write("log = " + str(log2))
thingy6.close()
else:
print ("receiver ID does not exist.")
def printLog():
thingy = (len(log2))
for x in range(thingy):
print(log2[x])
print ("")
a = test() #account ID 0
b = test() #account ID 1
c = test() #account ID 2
d = test() #account ID 3
b.py:
bList = [5000, 5000, 5000, 5000]
d.py:
dList = [0, 0, 0 ,0]
l.py:
log = []
s.py:
sList = [0, 1, 2, 3]
所以基本上,b.py是所有余额的清单, d.py是任何人从过度提款中获得的所有/任何债务的清单,l.py只是一个日志,以便记录任何存款,取款或交易,而s.py是每个账户ID的列表,以确定是否或者不是帐户应该经历多个默认值的设置过程(余额为5000,债务为0)。
要改写一下,我想要做的是在我的代码中添加一些内容,而不会做太多改动,以便执行以下操作:
1)创建人民存款的复利,每周增加一次 2)有某种地方撤回资金到每个帐户绑定(这显然没有兴趣) 3)创建人民债务的复利,每周支付一次 4)当许多人开户时,银行有某种方式赚取利润,使经济增长 5)让日志提及提款/存款/交易的时间
这有点多了,但我很难知道所有这些事情的起点。