Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
666
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.40 KB | None | 0 0
  1. import datetime as dt
  2.  
  3. class Calculator:
  4.     records = []
  5.     def __init__(self, limit, date = ' '):
  6.         self.limit = limit
  7.         self.count = 0
  8.         self.date = Date.formate_date(self, date)
  9.        
  10.    
  11.     def add_record(self, record):
  12.         #self.count += record.amount
  13.         self.records.append(record)
  14.         for item in self.records:
  15.             print(item.amount)
  16.        
  17.        
  18.     #def get_week_stats():
  19.    
  20. class CashCalculator(Calculator):
  21.     def __init__(self, limit):
  22.        super().__init__(limit)
  23.        self.count = 0
  24.        print(f'Создан калькулятор денег с лимитом {self.limit}')
  25.    
  26.     def add_record(self, record):
  27.         super().add_record(record)
  28.     # def get_today_cash_remained(self, currency):
  29.     #     for n in range
  30.     #     remained = self.limit
  31.        
  32.         #for n in range(len(self.records)):
  33.          #   spent += str(self.records[n,0])
  34.        
  35.    
  36.    #def get_today_stats():
  37.    
  38.    
  39. class Record(CashCalculator):
  40.     def __init__(self, amount, comment, date = ' '):
  41.         self.amount = amount
  42.         self.comment = comment
  43.         self.date = Date.formate_date(self, date)   # Вопрос: почему еще и self должен передавать?
  44.         # Проверка создания записи
  45.         #print(f'Создана запись! Затраты: {self.amount}, комментарий: "{self.comment}", дата - {self.date}')
  46.  
  47.     def show(self):
  48.         print(f'Создана запись! Затраты: {self.amount}, комментарий: "{self.comment}", дата - {self.date}')
  49.  
  50. # Класс для форматирования даты
  51. class Date:
  52.     def formate_date(self, date):
  53.         if date == " ":
  54.             now = dt.datetime.now()
  55.             date = now.date()
  56.         elif date != " ":
  57.             date_format = '%d.%m.%Y'
  58.             moment = dt.datetime.strptime(date, date_format)
  59.             date = moment.date()
  60.         return date
  61.  
  62. # Тесты
  63. #r1 = Record(amount = 145, comment = "Безудержный шопинг", date = '08.11.2019')
  64. #r2 = Record(amount=84, comment="Йогурт.", date="23.02.2019")
  65. #r1.show()
  66. #r2.show()
  67.  
  68. cash_calculator = CashCalculator(1000)
  69. cash_calculator.add_record(Record(amount=145, comment="кофе"))
  70. cash_calculator.add_record(Record(amount=300, comment="Серёге за обед"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement