From 4b7da2f4e72d4ddde9fb2b5dc7bee376ce48622c Mon Sep 17 00:00:00 2001 From: Artem Prigodsky Date: Mon, 14 Dec 2020 10:12:39 +0800 Subject: [PATCH] lession2 --- task_1.py | 5 +++++ task_2.py | 11 +++++++++++ task_3.py | 31 +++++++++++++++++++++++++++++++ task_4.py | 9 +++++++++ task_5.py | 16 ++++++++++++++++ task_6.py | 33 +++++++++++++++++++++++++++++++++ 6 files changed, 105 insertions(+) create mode 100644 task_1.py create mode 100644 task_2.py create mode 100644 task_3.py create mode 100644 task_4.py create mode 100644 task_5.py create mode 100644 task_6.py diff --git a/task_1.py b/task_1.py new file mode 100644 index 0000000..0714fa0 --- /dev/null +++ b/task_1.py @@ -0,0 +1,5 @@ +my_list = [10, 67.2, 'string', True] + +for item in my_list: + print(type(item)) + diff --git a/task_2.py b/task_2.py new file mode 100644 index 0000000..e297394 --- /dev/null +++ b/task_2.py @@ -0,0 +1,11 @@ +txt_input = input("Перечислите элементы списка через запятую (1,2,3): ") +arr_input = txt_input.split(",") + +length = len(arr_input) +for key, item in enumerate(arr_input): + if key % 2 == 0 and key + 1 < length: + save = item + arr_input[key] = arr_input[key + 1] + arr_input[key + 1] = save + +print(arr_input) diff --git a/task_3.py b/task_3.py new file mode 100644 index 0000000..298d42d --- /dev/null +++ b/task_3.py @@ -0,0 +1,31 @@ +month = int(input("Введите число месяца: ")) + +if month == 0 or month > 12: + print("Неверный формат месяца") +else: + # list + winter = [12, 1, 2] + spring = [3, 4, 5] + summer = [6, 7, 8] + autumn = [9, 10, 11] + + if month in winter: + print("Это зима, бро") + if month in spring: + print("Это весна, бро") + if month in summer: + print("Это лето, бро") + if month in autumn: + print("Это осень, бро") + + # dict + month_data = { + 'зима': [12, 1, 2], + 'весна': [3, 4, 5], + 'лето': [6, 7, 8], + 'осень': [9, 10, 11] + } + for m_key in month_data: + if month in month_data[m_key]: + print(f"Это {m_key}, бро") + break diff --git a/task_4.py b/task_4.py new file mode 100644 index 0000000..a87e9fb --- /dev/null +++ b/task_4.py @@ -0,0 +1,9 @@ +my_str = input("Введите предложение: ") +words = my_str.split(" ") + +i = 1 +for word in words: + if len(word) > 10: + word = word[:10] + print(f"{i}: {word}") + i += 1 diff --git a/task_5.py b/task_5.py new file mode 100644 index 0000000..d884c4a --- /dev/null +++ b/task_5.py @@ -0,0 +1,16 @@ +i_num = int(input("Введите число рейтинга: ")) +my_list = [7, 5, 3, 3, 2] + +i = 0 +update = False +for item in my_list: + if i_num >= item: + my_list.insert(i, i_num) + update = True + break + i += 1 + +if not update: + my_list.append(i_num) + +print(my_list) diff --git a/task_6.py b/task_6.py new file mode 100644 index 0000000..66d921c --- /dev/null +++ b/task_6.py @@ -0,0 +1,33 @@ +products = [] + +while True: + p_name = input("Введите название товара: ") + p_cost = input("Введите цену товара: ") + p_count = input("Введите количество товара: ") + p_it = input("Введите единицу измерения товара: ") + product = { + 'название': p_name, + 'цена': p_cost, + 'количество': p_count, + 'ед': p_it, + } + product_id = len(products) + 1 + product_item = (product_id, product) + products.append(product_item) + print(products) + + # аналитика + a_names = set() + a_costs = set() + a_counts = set() + a_it = set() + for item in products: + a_names.add(item[1]['название']) + a_costs.add(item[1]['цена']) + a_counts.add(item[1]['количество']) + a_it.add(item[1]['ед']) + + print(a_names) + print(a_costs) + print(a_counts) + print(a_it)