Bank Account in Python
Posted by Samath
Last Updated: April 23, 2015

Decide on a way to represent a tagged Abstract Data Type called Bank Account. The data stored on a Bank Account are:
a) Account Number
b) Account Owner
c) Balance

2. Define the following methods for your ADT:

def makeAccount1(accNum, accOwn):
    return ['bAccount', accNum,accOwn,0]

def makeAccount2(accNum, accOwn, sBalance):
    return ['bAccount', accNum,accOwn,sBalance]

def getAccNumber(acc):
    return acc[1]

def getAccountName(acc):
    return acc[2]

def getAccountBalance(acc):
    return acc[3]

def changeName(name, acc):
    if(name != acc[2]):
        acc[2] = name

def isAccount(acc):
    if acc[0] == "bAccount":
        return True
        return False

def isBalanceEnough(acc,amt):
        return True
        return False

Write functions to do the following:
a) Withdraw an amount from a given account, if sufficient money is available. 

def withdraw(acc, amt):

b) Deposit an amount into a given account. 

def deposit(acc, amt):

c) Transfer money from a valid account to another valid account. Transference should ONLY be done if sufficient money is in the account.

def transfer(fromAcc, toAcc, amt):
    if(isAccount(fromAcc) and isAccount(toAcc)):
            withdraw(fromAcc, amt)
            deposit(toAcc, amt)

This question focuses on collections of Bank Accounts:
a) Choose to represent your collection of bank Account as a Stack or Queue.

def stackAccount():
    return ('stack',[])

b) Write the relevant methods needed to (correct naming of your methods is extremely important):
i. Add an Account to the collection 

def addAccount(stack_i,acc):

ii. Remove an Account from the collection 

def removeAccount(stack_i):

iii. Check what account is at the front or top 

def top(stk):
        return stk[1][0]

iv. Check if the collection is empty 

def is_empty(stack_i):
                return True

v. Output all account information (Formatting of output is important) 

def outputAccountFromStack(stk):
    for a in stk[1]:
        print("Account Number: "+getAccNumber(a)+" Name: "+getAccountName(a)+" Balance: "+str(getAccountBalance(a)))

5. Write a main method to do the following:
a) Accept account information and add your collection. (NB: Use a loop and ensure you allow ONLY valid accounts to the collection ) 
b) Charge a balance deduction fee of $500, for accounts with less than $2000 balance.
c) Charge a general 1% bank charges fee to ALL accounts.

def main():

    accountGroup = stackAccount()

        accNum = input("Enter account number: ")
        accName = input("Enter account name: ")
        accBalance = int(input("Enter account balance: "))

        myAccount = makeAccount2(accNum, accName, accBalance)

            print("Invalid Account... Try Again")

        option = input("Enter Y to Add more Account N to Quit: ")
        if(option == 'Y' or option == 'y'):
        elif(option == 'N' or option == 'n'):

    for acc in accountGroup[1]:
        abal = getAccountBalance(acc)
        if(abal < 2000):
            withdraw(acc, 500)

    for acc in accountGroup[1]:
        abal = getAccountBalance(acc)
        charge = 0.01 * abal
        withdraw(acc, charge)



Related Content
Account Class in C++
Account Class in C++
Samath | Jan 07, 2021
Bank Management System in C++
Bank Management System in C++
Samath | Jan 01, 2021