Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class BankAccount(object):
- balance = 0
- def __init__(self, name):
- self.name = name
- def __repr__(self):
- return "Cuenta de %s. Balance: $%.2f" % (self.name, self.balance)
- def show_balance(self):
- print "Tu balance es: $%.2f " % (self.balance)
- def deposit(self, amount):
- if amount <= 0 :
- print "Ingrese una suma"
- return
- else:
- print "Se depositaron $%.2f" % (amount)
- self.balance += amount
- self.show_balance()
- def withdraw(self, amount):
- if amount > self.balance:
- return "El monto excede su saldo"
- else:
- print "Se retiraron $%.2f" % (amount)
- self.balance -= amount
- self.show_balance()
- my_account = BankAccount("Tomas")
- print my_account
- print my_account.show_balance()
- my_account.deposit(2000)
- my_account.withdraw(1000)
- print my_account
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement