-
-
Save codecademydev/b2c84b960cd11373b6ac9b1aca46ef69 to your computer and use it in GitHub Desktop.
Codecademy export
This file contains 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
class BankAccount(object): | |
balance = 0 | |
def __init__(self, name): | |
self.name = name | |
def __repr__(self): | |
print "This account belongs to %s and has a balance of $ %.2f" % (self.name, self.balance) | |
def show_balance(self): | |
print "Your total balance is $%.2f" % self.balance | |
def deposit(self, amount): | |
if amount <= 0 : | |
print "Invalid deposit" | |
return | |
else : | |
print "You are depositing $ %.2f" % amount | |
self.balance += amount | |
self.show_balance() | |
def withdraw(self, amount): | |
if amount > self.balance : | |
print "Error, you can't withdraw more than you have dummy!" | |
return | |
else : | |
print "You are withdrawing $%.2f" % amount | |
self.balance -= amount | |
self.show_balance() | |
my_account = BankAccount("Mike") | |
print my_account | |
my_account.show_balance() | |
my_account.deposit(2000) | |
my_account.withdraw(1000) | |
print my_account | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment