Skip to content

Instantly share code, notes, and snippets.

@Stealthii
Created July 15, 2013 19:16
Show Gist options
  • Save Stealthii/6002584 to your computer and use it in GitHub Desktop.
Save Stealthii/6002584 to your computer and use it in GitHub Desktop.
Braun Brelin's account code
class account():
""" This is a class that defines bank accounts
"""
MIN_DEPOSIT_AMOUNT=1.00
MIN_INITIAL_BALANCE_AMT=10.00
account_number=""
opening_branch=""
balance=0.0
accountholder=""
def __init__(self,**kwargs):
self.account_number = kwargs["account_number"]
self.opening_branch = kwargs["opening_branch"]
if (kwargs["opening_balance"] < self.MIN_INITIAL_BALANCE_AMT):
return(False)
self.balance=kwargs["opening_balance"]
self.accountholder=kwargs["account_holder"]
def deposit(self,deposit_amount):
if (deposit_amount < self.MIN_DEPOSIT_AMOUNT):
return(False)
self.balance = self.balance + deposit_amount
return (True)
def withdraw(self,withdrawal_amount):
if (self.balance - withdrawal_amount > 0):
self.balance = self.balance - withdrawal_amount
else:
return(False)
return(True)
def getbalance(self):
return(self.calculate_balance())
def calculate_balance(self):
return(self.balance)
class current_account(account):
overdraft=0.0
MINIMUM_OVERDRAFT_LIMIT=500
def __init__(self,**kwargs):
try:
self.overdraft = kwargs["initial_overdraft"]
except KeyError:
self.overdraft = self.MINIMUM_OVERDRAFT_LIMIT
finally:
account.__init__(self,**kwargs)
def setOverdraftLimit(self,amount_to_increase):
try:
self.overdraft = self.overdraft + amount_to_increase
except TypeError:
return(False)
return(True)
def getOverdraftLimit(self):
return(self.overdraft)
class savings_account(account):
interest_rate=0.0
MINIMUM_INTEREST_RATE=0.04
def __init__(self,**kwargs):
try:
self.interest_rate = kwargs["interest_rate"]
except KeyError:
self.interest_rate = self.MINIMUM_INTEREST_RATE
finally:
account.__init__(self,**kwargs)
def calculate_new_balance(self):
self.balance = self.balance + self.balance * self.interest_rate
#!/usr/bin/env python
import sys
from account_classes import account,current_account,savings_account
account_dictionary = {}
function_dictionary = {}
def create_current_account():
a_id = raw_input("Please enter the account id")
while (1):
try:
a_balance = float(raw_input("Please enter the initial balance: "))
except ValueError:
print "Invalid balance"
continue
if (a_balance == -1):
return(False)
ah_name=raw_input("Please enter the account holders name")
while (1):
try:
a_overdraft = float(raw_input("Please enter the initial overdraft: "))
except ValueError:
print "Invalid overdraft"
continue
if (a_overdraft = -1):
return(False)
ob = raw_input("Please enter the opening branch: ")
cur_obj = current_account(account_id = a_id, account_holder = ah_name,opening_balance=ob,initial_overdraft=a_overdraft,opening_branch=ob)
account_dictionary[a_id] = cur_obj
cur_acct = current_account(
def create_savings_account():
pass
def add_account():
a_id = raw_input("Please enter the account id: ")
if not account_dictionary[a_id]:
print "error"
return(False)
try:
deposit_amt = float(raw_input("Enter the amount to deposit: "))
except ValueError:
print "Invalid deposit amount"
return(False)
if (deposit_amt < -0):
print "Invalid deposit amount"
return(False)
account_dictionary[a_id].deposit(deposit_amt)
return(True)
pass
def subtract_account():
pass
def exit_routine():
try:
f = open("account_output.dat","wb+")
except IOError,err:
print "ERROR: ",str(err)
sys.exit(1)
pickle.dump(account_dictionary,f)
sys.exit(0)
def initialize():
try:
f = open("account_output.dat","rb")
except IOError,err:
print "ERROR: ",str(err)
sys.exit(1)
account_dictionary = pickle.load(f)
function_dictionary={1:create_current_account,2:create_savings_account,3:add_account,4:subtract_account,5:view_account,6:exit_routine)
while (1):
print "Press 1. To create a Current Account"
print "Press 2. To create a Savings Accoungt"
print "Press 3. To add to account"
print "Press 4. To subtract from account"
print "Press 5. To view account details"
print "Press 6. To exit"
input = int(raw_input())
function_dictionary[input]()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment