Created
November 24, 2016 16:04
-
-
Save mediboinadp/59713c7ad7b4cc43806a662f2aa58cb5 to your computer and use it in GitHub Desktop.
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
class BankAccount(object): | |
balance = 0 | |
def __init__(self, name): | |
self.name = name | |
def __repr__(self): | |
return "%s's account. Balance: $%.2f" % (self.name, self.balance) | |
def show_balance(self): | |
print "Balance: $%.2f" % (self.balance) | |
def deposit(self, amount): | |
if amount <= 0: | |
print "Balance cannot be zero or less" | |
return | |
else: | |
print "Deposit: $%.2f" % (self.amount) | |
self.balance += amount | |
self.show_balance() | |
def withdraw(self, amount): | |
if amount > self.balance: | |
print "You do not have that much of moeny" | |
return | |
else: | |
self.balance -= amount | |
self.show_balance() | |
my_account = BankAccount("Prasad") | |
print my_account | |
show_balance(my_account) | |
deposit(my_account, 2000) | |
withdraw(my_account, 1000) | |
print my_account |
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
class BankAccount(object): | |
balance = 0 | |
def __init__(self, name): | |
self.name = name | |
def __repr__(self): | |
return "%s's account. Balance: $%.2f" % (self.name, self.balance) | |
def show_balance(self): | |
print "Balance: $%.2f" % (self.balance) | |
def deposit(self, amount): | |
if amount <= 0: | |
print "Balance cannot be zero or less" | |
return | |
else: | |
print "Deposit: $%.2f" % (self.amount) | |
self.balance += amount | |
self.show_balance() | |
def withdraw(self, amount): | |
if amount > self.balance: | |
print "You do not have that much of moeny" | |
return | |
else: | |
self.balance -= amount | |
self.show_balance() | |
my_account = BankAccount("Prasad") | |
print my_account | |
show_balance(my_account) | |
deposit(my_account, 2000) | |
withdraw(my_account, 1000) | |
print my_account |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment