I have to write a program to process a file of many bank transactions. The data file we have to use with the program goes like this: The first line of the file indicates the number of bank accounts. If the first line is ‘x’ – then the next ‘x*2’ lines are pairs of data containing: • bank account number • current balance I have to create a bank account object and put them in a list. Following these lines are an unknown number of “sets” of data for transactions. Each transaction consists of: transaction type (W,D,T or B) account number(s) amount The sentinel value is a transaction type of “#”. This is what my code looks like so far:
class BankAccount:
def __init__(self, inputNum, inputAmount):
self.__acctNum = inputNum
self.__balance = inputAmount
self.__numDeposits = 0
self.__totalDeposits = 0
self.__numWithdrawals = 0
self.__totalWithdrawals = 0
def getAcctNum(self):
return self.__acctNum
def getBalance(self):
return self.__balance
def getNumDeposits(self):
return self.__numDeposits
def getNumWithdrawals(self):
return self.__numWithdrawals
def getTotalDeposits(self):
return self.__totalDeposits
def getTotalWithdrawals(self):
return self.__totalWithdrawals
def Deposit(self,amount):
self.__balance = self.__balance + amount
self.__numDeposits = self.__numDeposits + 1
self.__totalDeposits = self.__totalDeposits + amount
def Withdrawal(self,amount):
if (self.__balance >= amount):
self.__balance = self.__balance - amount
self.__numWithdrawals = self.__numWithdrawals + 1
self.__totalWithdrawals = self.__totalWithdrawals + amount
return True
else:
return False
def main():
list1 = []
num = eval(input())
for i in range(num):
account = input()
amount = eval(input())
bankAccount = BankAccount(account,amount)
list1.append(bankAccount)
print(list1[i].getBalance())
while(type != '#'):
if(type == 'D'):
account.deposit(amount)
elif(type == 'W'):
elif(type == 'T'):
elif(type == 'B'):
First question: Do list1 and num = eval(input()) go before the main function, or is it good like it is? Second question: Where would type = eval(input()) go? I'm guessing it would go right after the list1 and num? Also, if you could give me some suggestions or tips on how to finish this program, I'd really appreciate it!
float()instead ofeval