-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
70 lines (53 loc) · 2.36 KB
/
main.py
File metadata and controls
70 lines (53 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import datetime as dt
class Record:
def __init__(self, amount, comment, date=''):
self.amount = amount
self.date = (
dt.datetime.now().date() if
not
date else dt.datetime.strptime(date, '%d.%m.%Y').date())
self.comment = comment
class Calculator:
def __init__(self, limit):
self.limit = limit
self.records = []
def add_record(self, record):
self.records.append(record)
def get_today_stats(self):
return sum([rec.amount for rec in self.records if rec.date == dt.datetime.now().date()])
def get_week_stats(self):
today = dt.datetime.now().date()
return sum([rec.amount for rec in self.records if 7 > (today - rec.date).days >= 0])
class CaloriesCalculator(Calculator):
def get_calories_remained(self): # Получает остаток калорий на сегодня
x = self.limit - self.get_today_stats()
if x > 0:
return f'Сегодня можно съесть что-нибудь' \
f' ещё, но с общей калорийностью не более {x} кКал'
else:
return ('Хватит есть!')
class CashCalculator(Calculator):
USD_RATE = float(60) # Курс доллар США.
EURO_RATE = float(70) # Курс Евро.
def get_today_cash_remained(self, currency,
USD_RATE=USD_RATE, EURO_RATE=EURO_RATE):
cash_remained = self.limit - self.get_today_stats()
d = {'usd': (USD_RATE, 'USD'), 'eur': (EURO_RATE, 'Euro'), 'rub': (1.0, 'руб')}
rate = d.get(currency)
if rate is None:
return f'Неизвестная валюта {currency}'
cash_remained /= rate[0]
currency_type = d.get(currency)[1]
if cash_remained > 0:
return (
f'На сегодня осталось {round(cash_remained, 2)} '
f'{currency_type}'
)
elif cash_remained == 0:
return 'Денег нет, держись'
elif cash_remained < 0:
return 'Денег нет, держись:' \
' твой долг - {0:.2f} {1}'.format(-cash_remained,
currency_type)
def get_week_stats(self):
super().get_week_stats()