Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import datetime as dt
- class Calculator:
- records = []
- def __init__(self, limit, date = ' '):
- self.limit = limit
- self.count = 0
- self.date = Date.formate_date(self, date)
- def add_record(self, record):
- #self.count += record.amount
- self.records.append(record)
- for item in self.records:
- print(item.amount)
- #def get_week_stats():
- class CashCalculator(Calculator):
- def __init__(self, limit):
- super().__init__(limit)
- self.count = 0
- print(f'Создан калькулятор денег с лимитом {self.limit}')
- def add_record(self, record):
- super().add_record(record)
- # def get_today_cash_remained(self, currency):
- # for n in range
- # remained = self.limit
- #for n in range(len(self.records)):
- # spent += str(self.records[n,0])
- #def get_today_stats():
- class Record(CashCalculator):
- def __init__(self, amount, comment, date = ' '):
- self.amount = amount
- self.comment = comment
- self.date = Date.formate_date(self, date) # Вопрос: почему еще и self должен передавать?
- # Проверка создания записи
- #print(f'Создана запись! Затраты: {self.amount}, комментарий: "{self.comment}", дата - {self.date}')
- def show(self):
- print(f'Создана запись! Затраты: {self.amount}, комментарий: "{self.comment}", дата - {self.date}')
- # Класс для форматирования даты
- class Date:
- def formate_date(self, date):
- if date == " ":
- now = dt.datetime.now()
- date = now.date()
- elif date != " ":
- date_format = '%d.%m.%Y'
- moment = dt.datetime.strptime(date, date_format)
- date = moment.date()
- return date
- # Тесты
- #r1 = Record(amount = 145, comment = "Безудержный шопинг", date = '08.11.2019')
- #r2 = Record(amount=84, comment="Йогурт.", date="23.02.2019")
- #r1.show()
- #r2.show()
- cash_calculator = CashCalculator(1000)
- cash_calculator.add_record(Record(amount=145, comment="кофе"))
- cash_calculator.add_record(Record(amount=300, comment="Серёге за обед"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement