Skip to content

Commit 137f26a

Browse files
committed
Calculator (updated) v.3
1 parent 0b0d668 commit 137f26a

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

homework.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,20 @@ def get_week_date(self):
2525
return self.get_today_date() - dt.timedelta(days=7)
2626

2727
def add_record(self, record):
28-
self.records.append(record)
28+
return self.records.append(record)
2929

3030
def get_today_stats(self):
31-
t_amount = []
32-
for record in self.records:
33-
if record.date == self.get_today_date():
34-
t_amount.append(record.amount)
31+
today = self.get_today_date()
32+
t_amount = [record.amount for record in self.records
33+
if record.date == today]
3534
return sum(t_amount)
3635

3736
def get_week_stats(self):
38-
total_week_amount = []
39-
for record in self.records:
40-
if self.get_today_date() >= record.date > self.get_week_date():
41-
total_week_amount.append(record.amount)
42-
return sum(total_week_amount)
37+
today = self.get_today_date()
38+
week_ago = self.get_week_date()
39+
week_amount = [record.amount for record in self.records
40+
if today >= record.date > week_ago]
41+
return sum(week_amount)
4342

4443
def get_today_limit(self):
4544
return self.limit - self.get_today_stats()
@@ -59,19 +58,17 @@ def get_today_cash_remained(self, currency):
5958
currencies = {'rub': ('руб', 1),
6059
'usd': ('USD', CashCalculator.USD_RATE),
6160
'eur': ('Euro', CashCalculator.EURO_RATE)}
62-
63-
c_type, c_rate = currencies[currency]
64-
6561
if self.currency not in currencies:
6662
return 'Указана неверная валюта. Повторите ввод.'
63+
c_type, c_rate = currencies[currency]
64+
6765
if t_amount == 0:
6866
return 'Денег нет, держись'
6967
if t_amount > 0:
7068
return (f'На сегодня осталось '
7169
f'{abs(round((t_amount / c_rate), 2))} {c_type}')
72-
else:
73-
return (f'Денег нет, держись: твой долг - '
74-
f'{abs(round((t_amount / c_rate), 2))} {c_type}')
70+
return (f'Денег нет, держись: твой долг - '
71+
f'{abs(round((t_amount / c_rate), 2))} {c_type}')
7572

7673

7774
class CaloriesCalculator(Calculator):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy