Skip to content

Instantly share code, notes, and snippets.

@mediboinadp
Created November 24, 2016 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mediboinadp/59713c7ad7b4cc43806a662f2aa58cb5 to your computer and use it in GitHub Desktop.
Save mediboinadp/59713c7ad7b4cc43806a662f2aa58cb5 to your computer and use it in GitHub Desktop.
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
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