Hey all, want to share my work regarding a Bank teller project I worked on.
I started by writing some definite variables. Of course, the numbers itself is whatever you want them to be
checking_balance = 500
savings_balance = 10000
Followed by my ‘check balance’ functions
def check_balance(account_type, checking_balance, savings_balance):
if account_type == "savings":
balance = savings_balance
balance_statement = "Your {account_type} is ${balance}".format(account_type = account_type, balance = balance)
return balance_statement
elif account_type == "checking":
balance = checking_balance
balance_statement = "Your {account_type} is ${balance}".format(account_type = account_type, balance = balance)
return balance_statement
else:
return "Unsucessful, please select \"checking\" or \"savings\""
balance_statement = "Your {account_type} is ${balance}".format(account_type = account_type, balance = balance)
return balance_statement
elif account_type == "checking":
balance = checking_balance
balance_statement = "Your {account_type} is ${balance}".format(account_type = account_type, balance = balance)
return balance_statement
else:
return "Unsucessful, please select \"checking\" or \"savings\""
Then my deposit functions
#Deposit
def make_deposit(account_type, amount, checking_balance, savings_balance):
deposit_status = ""
if amount > 0:
if account_type == "savings":
savings_balance += amount
deposit_status = "successful!"
elif account_type == "checking":
checking_balance += amount
deposit_status = "successful!"
else:
deposit_status = "unsuccessful, please select \"checking\" or \"savings\""
else:
deposit_status = "unsuccessful, please enter an amount greater than 0"
deposit_statement = "Deposit of ${amount} to your {account_type} account was {deposit_status}".format(amount = amount, account_type = account_type, deposit_status = deposit_status)
print(deposit_statement)
if account_type == "savings":
return savings_balance
elif account_type == "checking":
return checking_balance
else:
return deposit_status
Next is my withdrawal functions:
#Withdrawal
def make_withdrawal(account_type, amount, checking_balance, savings_balance):
withdrawal_status = ""
fail = "unsuccessful, please enter amount less than balance"
if account_type == "savings":
if amount <= savings_balance:
savings_balance -= amount
withdrawal_status = "successful!"
else:
withdrawal_status = fail
elif account_type == "checking":
if amount <= checking_balance:
checking_balance -= amount
withdrawal_status = "successful!"
else:
withdrawal_status = fail
else:
withdrawal_status = "unsuccessful, please select \"checking\" or \"savings\""
withdrawal_statement = "Withdrawal of ${amount} from your {account_type} is {withdrawal_status}".format(amount = amount, account_type = account_type, withdrawal_status = withdrawal_status)
print(withdrawal_statement)
if account_type == "savings":
return savings_balance
elif account_type == "checking":
return checking_balance
else:
return withdrawal_status
Then my transfer functions
#Transfer
def acc_transfer(acc_from, acc_to, amount, checking_balance, savings_balance):
transaction_status = ""
trans_error = "unsuccessful, please enter amount less than "
if acc_from == "savings" and acc_to == "checking":
if savings_balance >= amount:
savings_balance -= amount
checking_balance += amount
transaction_status = "successful!"
else:
transaction_status = trans_error + str(savings_balance)
elif acc_from == "checking" and acc_to == "savings":
if checking_balance >= amount:
checking_balance -= amount
savings_balance += amount
transaction_status = "successful!"
else:
transaction_status = trans_error + str(checking_balance)
else:
transaction_status = "unsuccessful, please select \"checking\" or \"savings\""
print(transaction_status)
transaction_statement = "transfer of ${amount} from your {acc_from} to your {acc_to} account was {transaction_status}".format(amount = amount, acc_from = acc_from, acc_to = acc_to, transaction_status = transaction_status)
print(transaction_statement)
return savings_balance, checking_balance
And lastly, my calls functions to confirm everything was up to snuff
#Updating the balances per transaction
savings_balance = make_withdrawal("savings", 10, checking_balance, savings_balance)
print(check_balance("savings", checking_balance, savings_balance))
checking_balance = make_deposit("checking",200, checking_balance, savings_balance)
print(check_balance("checking", checking_balance, savings_balance))
savings_balance, checking_balance = acc_transfer("checking","savings", 40, checking_balance, savings_balance)
print(check_balance("checking", checking_balance, savings_balance))
print(check_balance("savings", checking_balance, savings_balance))
savings_balance, checking_balance = acc_transfer("savings","checking", 5, checking_balance, savings_balance)
print(check_balance("checking", checking_balance, savings_balance))
print(check_balance("savings", checking_balance, savings_balance))
The instructions have been kinda unhelpful at times but I am proud that I was able to fill in the banks myself (and the internet lol)