Skip to content
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

Homework1 task3 #168

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion 1_if1.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,28 @@
* Вывести содержимое переменной на экран

"""
def age_detector(age_input):
#activity_to_do =
if age_input < 7:
activity_to_do = 'Пользователь должен ходить в садик!'
elif age_input >= 7 and age_input < 16:
activity_to_do = 'Пользователь должен учиться в школе!'
elif age_input >= 16 and age_input < 21:
activity_to_do = 'Пользователь должен учиться в ВУЗе!'
else: #age_input >= 21:
activity_to_do = 'Пользователь должен работать!'
return activity_to_do

def main():
"""
Эта функция вызывается автоматически при запуске скрипта в консоли
В ней надо заменить pass на ваш код
"""
pass
age = int(input('Сколько Вам лет? '))
print('Ваш возраст:', age, 'лет!')
activity = age_detector(age)
#return age
print(activity)

if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions 2_if2.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
и выводя на экран результаты

"""
#Здесь я буду писать свою функцию!

def main():
"""
Expand Down
60 changes: 59 additions & 1 deletion 3_for.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Домашка номер 3!
"""

Домашнее задание №1
Expand All @@ -15,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():
"""
Эта функция вызывается автоматически при запуске скрипта в консоли
В ней надо заменить 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))
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()
1 change: 1 addition & 0 deletions learn-homework-1
Submodule learn-homework-1 added at 073440