0

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!

2
  • 3
    Don't give your money to any bank that allows user input to be eval()'ed. :) Commented May 3, 2013 at 20:30
  • 1
    use float() instead of eval Commented May 3, 2013 at 20:31

1 Answer 1

3

Unlike C, java, C# etc there is actually no strict need for the main function. You can actually remove the entire main function block and write it as plain lines of instructions.

If you really want to have the main function but also run the program as a script you can use in the end:

if __name__ == "__main__":
   main()

So the answer to your 1st question is: Anyway you like

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.