Autoteller Console
auto teller console.py
from Bank import *
cash_r_us = Bank()
cash_r_us.createUser("Ricky", 50)
cash_r_us.createUser("Sue")
cash_r_us.deposit(0, 99)
cash_r_us.deposit(1, 800)
cash_r_us.displayAccount(0)
cash_r_us.displayAccount(1)
Bank.py
from Account import *
class Bank:
def __init__(self):
self.accounts = {}
self.accountNumber = 0 #unique number for every account
def displayAccount(self, accountNumber):
return("Account number: " + str(accountNumber) + "\n" +
"Username: " + str(self.accounts[accountNumber].username) + "\n" +
"Balance: $" + str(self.accounts[accountNumber].balance) + "\n")
#set balance default to $0 if it is not assigned a value when called:
def createUser(self, username, balance = 0):
#uses Account class, which acts as a "template" or blueprint for the account:
newAccount = Account(username, balance)
# store account in dictionary, using unique account number as key:
self.accounts[self.accountNumber] = newAccount
self.accountNumber += 1
# ^^ increment so the account number stays unique on creation
def deposit(self, accountNumber, amount):
self.accounts[accountNumber].balance += amount
Account.py
class Account:
def __init__(self, username, balance):
self.username = username
self.balance = balance
Note - all files must be saved in the same folder location for this program to work.
- create
Bank.withdraw(self, accountNumber, amount):method - prevent the withdraw method from withdrawing more money than i have in my account (so i should not be able to go into a negative balance).
- both deposit and withdraw methods should give me a receipt or balance.
- display all accounts in Bank class dictionary (sorted)
- add password to Account class
- add account protection to withdraw method (above) so that withdrawal cannot be completed without correctly supplied account password
transactionLog = []for Bank, that records all activity for all its customerstransactionLog = []for Account, that records specific activity for that specific account- when the user is created, their account number should be displayed to the screen. otherwise, they won't know which account number to deposit / withdraw from. please fix this.
- could we substitute a unique email address for a unique account number? if so, can you enable the accounts dictionary to check if the key (email) exists, and if not, it can add it as a new account.. otherwise return an error message.
- user proof the above code using exception handling.
if you are not enjoying object-oriented programming, that's cool, in which case please try the above exercises on the non object-oriented version:
auto teller not OOP.py
accounts = {}
accountNumber = 0 #unique number for every account
def displayAccount(accountNumber):
global accounts
print("Account number: " + str(accountNumber) + "\n" +
"Username: " + str(accounts[accountNumber][0]) + "\n" +
"Balance: $" + str(accounts[accountNumber][1]) + "\n")
#set balance default to $0 if it is not assigned a value when called:
def createUser(username, balance = 0):
#uses a list structure for the account:
newAccount = [username, balance]
# store account in dictionary, using unique account number as key:
global accountNumber
global accounts
accounts[accountNumber] = newAccount
accountNumber += 1
# ^^ increment so the account number stays unique on creation
def deposit(accountNumber, amount):
global accounts
accounts[accountNumber][1] += amount
createUser("Ricky", 50)
createUser("Sue")
deposit(0, 99)
deposit(1, 800)
displayAccount(0)
displayAccount(1)