Advertisement
Korotkodul

A. Часть 3. 12 месяцев

Feb 23rd, 2025 (edited)
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. import numpy as np
  2. import calendar
  3. months_list = np.array([calendar.month_name[i] for i in range(1, 13)])
  4.  
  5. class InconsistentDataError(Exception):
  6.     pass
  7.  
  8. def sort_month_names_by_profits(
  9.     amounts_of_sold_subscriptions: np.ndarray,
  10.     subscriptions_prices: np.ndarray,
  11.     ascending: bool = True,
  12. ) -> list[str]:
  13.     if amounts_of_sold_subscriptions.shape[1] != subscriptions_prices.shape[1]:
  14.         raise InconsistentDataError
  15.     income = amounts_of_sold_subscriptions * subscriptions_prices
  16.     income_per_month = np.sum(income, axis=1)
  17.     indices = np.argsort(income_per_month)
  18.     res = months_list[indices]
  19.     if not ascending:
  20.         res = res[::-1]
  21.     return res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement