Advertisement
Falexom

Untitled

Aug 2nd, 2021
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 KB | None | 0 0
  1. import datetime
  2. from datetime import datetime
  3. import pytz
  4.  
  5. WHITE = '\033[00m'
  6. GREEN = '\033[0;92m'
  7. RED = '\033[1;31m'
  8.  
  9. class Account:
  10.     def __init__(self, name, balance):
  11.         self.name = name
  12.         self.__balance = balance
  13.         self._history = []
  14.  
  15.     @staticmethod
  16.     def _get_courrent_time():
  17.         return pytz.utc.localize(datetime.utcnow())
  18.  
  19.     def deposit(self, amount):
  20.         self.__balance += amount
  21.         self.show_balance()
  22.         self._history.append((amount, self._get_courrent_time()))
  23.  
  24.     def withdraw(self, amount):
  25.         if self.__balance > amount:
  26.             self.__balance -= amount
  27.             print(f'You spent {amount} money')
  28.             self.show_balance()
  29.             self._history.append((-amount, self._get_courrent_time()))
  30.         else:
  31.             ptint('Not enough money')
  32.             self.show_balance()
  33.  
  34.  
  35.     def show_balance(self):
  36.         print(f'Balance: {self.__balance}')
  37.  
  38.     def show_history(self):
  39.         for amount, date in self._history:
  40.             if amount > 0:
  41.                 transaction = 'deposited'
  42.                 color = GREEN
  43.             else:
  44.                 transaction = 'withdrawn'
  45.                 color = RED
  46.             print(f'{color} {amount} {WHITE} {transaction} on {date.astimezone}')
  47.  
  48.  
  49. a = Account('Tester', 0)
  50. a.deposit(100)
  51. a.deposit(50)
  52.  
  53. a.deposit(150)
  54. a.withdraw(70) # OOP for retards
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement