Лови
import locale
from tabulate import tabulate
def calculate_exchange_rates(initial_rate, decline_percent, days, amount):
results = []
current_rate = initial_rate
for day in range(1, days + 1):
ruble_equivalent = amount * current_rate
results.append((day, current_rate, ruble_equivalent))
current_rate *= (1 - decline_percent / 100)
return results
def format_currency(value):
return locale.currency(value, grouping=True)
def main():
locale.setlocale(locale.LC_ALL, 'ru_RU.UTF-8')
try:
A = float(input("Введите текущий курс доллара (в рублях): "))
N = float(input("Введите сумму в долларах: "))
p = float(input("Введите процент ежедневного падения курса: "))
days = int(input("Введите количество дней для расчета (по умолчанию 10): ") or 10)
if A <= 0 or N <= 0 or p < 0 or days <= 0:
raise ValueError("Введены некорректные данные")
exchange_rates = calculate_exchange_rates(A, p, days, N)
table_data = [
[day, format_currency(rate), format_currency(ruble_amount), f"{(1 - rate/A)*100:.2f}%"]
for day, rate, ruble_amount in exchange_rates
]
headers = ["День", "Курс доллара", f"Эквивалент {N}$", "Падение курса"]
print(tabulate(table_data, headers=headers, tablefmt="grid"))
total_decline = (1 - exchange_rates[-1][1] / A) * 100
print(f"\nОбщее падение курса за {days} дней: {total_decline:.2f}%")
print(f"Средний курс доллара: {format_currency(sum(rate for _, rate, _ in exchange_rates) / days)}")
except ValueError as e:
print(f"Ошибка: {e}")
except locale.Error:
format_currency = lambda x: f"{x:.2f}"
main()
if __name__ == "__main__":
main()