Last active
March 5, 2017 04:09
-
-
Save jess010/164afac7b78e542716227dbb0bb27d6e to your computer and use it in GitHub Desktop.
Bank account class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create an object of type 'BankAccount' with methods appropriate for this object | |
class BankAccount: | |
def __init__(self, initial_balance): | |
self.balance = initial_balance | |
self.fees = 0 | |
def deposit(self, amount): | |
self.balance += amount | |
def withdraw(self, amount): | |
if self.balance - amount < 0: | |
self.balance -= amount + 5 | |
self.fees += 5 | |
else: | |
self.balance -= amount | |
def get_balance(self): | |
return self.balance | |
def get_fees(self): | |
return self.fees | |
my_account = BankAccount(10) | |
my_account.withdraw(5) | |
my_account.deposit(10) | |
my_account.withdraw(5) | |
my_account.withdraw(15) | |
my_account.deposit(20) | |
my_account.withdraw(5) | |
my_account.deposit(10) | |
my_account.deposit(20) | |
my_account.withdraw(15) | |
my_account.deposit(30) | |
my_account.withdraw(10) | |
my_account.withdraw(15) | |
my_account.deposit(10) | |
my_account.withdraw(50) | |
my_account.deposit(30) | |
my_account.withdraw(15) | |
my_account.deposit(10) | |
my_account.withdraw(5) | |
my_account.deposit(20) | |
my_account.withdraw(15) | |
my_account.deposit(10) | |
my_account.deposit(30) | |
my_account.withdraw(25) | |
my_account.withdraw(5) | |
my_account.deposit(10) | |
my_account.withdraw(15) | |
my_account.deposit(10) | |
my_account.withdraw(10) | |
my_account.withdraw(15) | |
my_account.deposit(10) | |
my_account.deposit(30) | |
my_account.withdraw(25) | |
my_account.withdraw(10) | |
my_account.deposit(20) | |
my_account.deposit(10) | |
my_account.withdraw(5) | |
my_account.withdraw(15) | |
my_account.deposit(10) | |
my_account.withdraw(5) | |
my_account.withdraw(15) | |
my_account.deposit(10) | |
my_account.withdraw(5) | |
print(my_account.get_balance(), my_account.get_fees()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment