Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import datetime
- from datetime import datetime
- import pytz
- WHITE = '\033[00m'
- GREEN = '\033[0;92m'
- RED = '\033[1;31m'
- class Account:
- def __init__(self, name, balance):
- self.name = name
- self.__balance = balance
- self._history = []
- @staticmethod
- def _get_courrent_time():
- return pytz.utc.localize(datetime.utcnow())
- def deposit(self, amount):
- self.__balance += amount
- self.show_balance()
- self._history.append((amount, self._get_courrent_time()))
- def withdraw(self, amount):
- if self.__balance > amount:
- self.__balance -= amount
- print(f'You spent {amount} money')
- self.show_balance()
- self._history.append((-amount, self._get_courrent_time()))
- else:
- ptint('Not enough money')
- self.show_balance()
- def show_balance(self):
- print(f'Balance: {self.__balance}')
- def show_history(self):
- for amount, date in self._history:
- if amount > 0:
- transaction = 'deposited'
- color = GREEN
- else:
- transaction = 'withdrawn'
- color = RED
- print(f'{color} {amount} {WHITE} {transaction} on {date.astimezone}')
- a = Account('Tester', 0)
- a.deposit(100)
- a.deposit(50)
- a.deposit(150)
- a.withdraw(70) # OOP for retards
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement