Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. class BankAccount(object):
  2. balance = 0
  3. def __init__(self, name):
  4. self.name = name
  5. def __repr__(self):
  6. return "Cuenta de %s. Balance: $%.2f" % (self.name, self.balance)
  7. def show_balance(self):
  8. print "Tu balance es: $%.2f " % (self.balance)
  9. def deposit(self, amount):
  10. if amount <= 0 :
  11. print "Ingrese una suma"
  12. return
  13. else:
  14. print "Se depositaron $%.2f" % (amount)
  15. self.balance += amount
  16. self.show_balance()
  17. def withdraw(self, amount):
  18. if amount > self.balance:
  19. return "El monto excede su saldo"
  20. else:
  21. print "Se retiraron $%.2f" % (amount)
  22. self.balance -= amount
  23. self.show_balance()
  24.  
  25. my_account = BankAccount("Tomas")
  26.  
  27. print my_account
  28.  
  29. print my_account.show_balance()
  30.  
  31. my_account.deposit(2000)
  32. my_account.withdraw(1000)
  33.  
  34. print my_account
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement