ivapopova

BankAccount Class

Mar 28th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. class BankAccount(object):
  2.     """Represent a simplified bank account
  3.  
  4.     Attributes:
  5.         balance (float): current balance
  6.         owner (string): owner name
  7.     """
  8.  
  9.     def __init__(self, owner_name, initial_balance, currency):
  10.         self.owner = owner_name
  11.         self.__balance = initial_balance
  12.         self.currency = currency
  13.  
  14.     def deposit(self, amount):
  15.         self.__balance += amount
  16.  
  17.     def withdraw(self, amount):
  18.         if amount > self.__balance:
  19.             print("Not enough funds!")
  20.             return False
  21.         else:
  22.             self.__balance -= amount
  23.  
  24.     def report(self):
  25.         print("{} has {}{}".format(self.owner, self.__balance, self.currency))
  26.  
  27.  
  28. maria_account = BankAccount("Maria", 0, "lv")
  29. pesho_account = BankAccount("Pesho", 0, "$")
  30.  
  31. maria_account.deposit(100)
  32. # change "hidden"  field:
  33. maria_account._BankAccount__balance = 1_000_000
  34. maria_account.report()
Add Comment
Please, Sign In to add comment