-
Notifications
You must be signed in to change notification settings - Fork 0
Task 3 is almost done. #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,13 +16,70 @@ | |
| * Посчитать и вывести суммарное количество продаж всех товаров | ||
| * Посчитать и вывести среднее количество продаж всех товаров | ||
| """ | ||
| def number_of_goods(sold_products, row): | ||
| number_of_sold = 0 | ||
| phones_sold_number = 0 | ||
| for number_of_sold in range(len(sold_products[row]['items_sold'])): | ||
| phones_sold_number += sold_products[row]['items_sold'][number_of_sold] | ||
| return phones_sold_number | ||
|
|
||
| def avg_number_of_goods(sold_products, row): | ||
| number_of_sold = 0 | ||
| phones_sold_number = 0 | ||
| average_sold = 0 | ||
| total_sold = len(sold_products[row]['items_sold']) | ||
| for number_of_sold in range(len(sold_products[row]['items_sold'])): | ||
| phones_sold_number += sold_products[row]['items_sold'][number_of_sold] | ||
| average_sold = int(phones_sold_number / total_sold) | ||
| return average_sold | ||
|
|
||
| def avg_number_of_all_goods(sold_products): | ||
| category = 0 | ||
| number_of_sold = 0 | ||
| phones_sold_number = 0 | ||
| average_sold = 0 | ||
| total_sold = len(sold_products['product']['items_sold']) | ||
| # total_sold = len(sold_products) | ||
| # total_sold = len(sold_products[],[]) | ||
| # print(total_sold) | ||
|
|
||
| # iphone_12_dict = dict(sold_products[0][1][]) | ||
| # print(iphone_12_dict) | ||
|
|
||
| # params = sold_products.get("items_sold") | ||
| print(sold_products) | ||
|
|
||
| for category in range(len(sold_products[category]['items_sold'])): | ||
| print("category = ", category) | ||
| print("Range of category:", range(len(sold_products[category]['items_sold']))) | ||
| for number_of_sold in range(len(sold_products[category]['items_sold'])): | ||
| print("number_of_sold = ", number_of_sold) | ||
| phones_sold_number += sold_products[category]['items_sold'][number_of_sold] | ||
| print(phones_sold_number) | ||
| average_sold = int(phones_sold_number / total_sold) | ||
| return average_sold | ||
|
|
||
| def main(): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1 и 2 пункт - можно просто в цикле по товарам посчитать и сразу вывести. |
||
| """ | ||
| Эта функция вызывается автоматически при запуске скрипта в консоли | ||
| В ней надо заменить pass на ваш код | ||
| """ | ||
| pass | ||
| sold_products = [ | ||
| {'product': 'iPhone 12', 'items_sold': [363, 500, 224, 358, 480, 476, 470, 216, 270, 388, 312, 186]}, | ||
| {'product': 'Xiaomi Mi11', 'items_sold': [317, 267, 290, 431, 211, 354, 276, 526, 141, 453, 510, 316]}, | ||
| {'product': 'Samsung Galaxy 21', 'items_sold': [343, 390, 238, 437, 214, 494, 441, 518, 212, 288, 272, 247]}, | ||
| ] | ||
| print("Кол-во проданных iPhone12: ", number_of_goods(sold_products, 0)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. надо делать так, чтоб можно было добалять или убирать товары, а функция работала |
||
| print("Кол-во проданных Xiaomi Mi11: ", number_of_goods(sold_products, 1)) | ||
| print("Кол-во проданных Samsung Galaxy 21: ", number_of_goods(sold_products, 2), "\n") | ||
|
|
||
| print("Среднее кол-во проданных iPhone12: ", avg_number_of_goods(sold_products, 0)) | ||
| print("Среднее кол-во проданных Xiaomi Mi11: ", avg_number_of_goods(sold_products, 1)) | ||
| print("Среднее кол-во проданных Samsung Galaxy 21: ", avg_number_of_goods(sold_products, 2), "\n") | ||
|
|
||
| print("Кол-во проданных Samsung Galaxy 21: ", number_of_goods(sold_products, 0) + number_of_goods(sold_products, 1) + number_of_goods(sold_products, 2), "\n") | ||
|
|
||
| # print("Среднее кол-во всех проданных устройств: ", avg_number_of_all_goods(sold_products)) | ||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
цикл можно проще сделать. Не обязательно итерироваться по индексам, можно же по значениям