From 9e174a3d466acdbce6bf4589b5ea02a9db34cfd9 Mon Sep 17 00:00:00 2001 From: Dmitriy Lobanov Date: Fri, 14 Feb 2020 16:58:42 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=BE=D0=B5?= =?UTF-8?q?=20=D0=B4=D0=B7=20=D0=BA=203=20=D1=83=D1=80=D0=BE=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lesson-2/lesson_2_task_1.py | 3 +++ lesson-2/lesson_2_task_2.py | 5 ++++ lesson-2/lesson_2_task_3.py | 29 +++++++++++++++++++++++ lesson-2/lesson_2_task_4.py | 6 +++++ lesson-2/lesson_2_task_5.py | 6 +++++ lesson-2/lesson_2_task_6.py | 40 +++++++++++++++++++++++++++++++ lesson-3/Readme.txt | 2 ++ lesson-3/leeson_3_task_1.py | 13 ++++++++++ lesson-3/lesson_3_task_2.py | 9 +++++++ lesson-3/lesson_3_task_3.py | 9 +++++++ lesson-3/lesson_3_task_4.py | 47 +++++++++++++++++++++++++++++++++++++ lesson-3/lesson_3_task_5.py | 22 +++++++++++++++++ lesson-3/lesson_3_task_6.py | 11 +++++++++ 13 files changed, 202 insertions(+) create mode 100644 lesson-2/lesson_2_task_1.py create mode 100644 lesson-2/lesson_2_task_2.py create mode 100644 lesson-2/lesson_2_task_3.py create mode 100644 lesson-2/lesson_2_task_4.py create mode 100644 lesson-2/lesson_2_task_5.py create mode 100644 lesson-2/lesson_2_task_6.py create mode 100644 lesson-3/Readme.txt create mode 100644 lesson-3/leeson_3_task_1.py create mode 100644 lesson-3/lesson_3_task_2.py create mode 100644 lesson-3/lesson_3_task_3.py create mode 100644 lesson-3/lesson_3_task_4.py create mode 100644 lesson-3/lesson_3_task_5.py create mode 100644 lesson-3/lesson_3_task_6.py diff --git a/lesson-2/lesson_2_task_1.py b/lesson-2/lesson_2_task_1.py new file mode 100644 index 0000000..e1a2fad --- /dev/null +++ b/lesson-2/lesson_2_task_1.py @@ -0,0 +1,3 @@ +my_list = ['строка', 8, 8.3, True, None, {5, 4, 8, 9}, {"age": 10, "name": "Leo"}, [], ()] +for el in my_list: + print(type(el), end=' ') diff --git a/lesson-2/lesson_2_task_2.py b/lesson-2/lesson_2_task_2.py new file mode 100644 index 0000000..7b2108b --- /dev/null +++ b/lesson-2/lesson_2_task_2.py @@ -0,0 +1,5 @@ +#user_list = [input("Введите элементы списка через запятую: ")] +user_list = ['строка', 8, 8.3, True, None, {"age": 10, "name": "Leo"}, [], ()] +user_list[::2], user_list[1::2] = user_list[1::2], user_list[::2] +print(user_list) + diff --git a/lesson-2/lesson_2_task_3.py b/lesson-2/lesson_2_task_3.py new file mode 100644 index 0000000..89ab6a4 --- /dev/null +++ b/lesson-2/lesson_2_task_3.py @@ -0,0 +1,29 @@ +#user_month = int(input("Введите месяц по счету, а я сообщу какое это время года: ")) +user_month = 9 +season = ["Зима", "Весна", "Лето", "Осень"] + + +if user_month == 1 or user_month == 2 or user_month == 12: + print(f'Время года {(season[0])}') +elif user_month == 5 or user_month == 4 or user_month == 3: + print(f'Время года {(season[1])}') +elif user_month == 6 or user_month == 7 or user_month == 8: + print(f'Время года {(season[2])}') +elif user_month == 9 or user_month == 10 or user_month == 11: + print(f'Время года {(season[3])}') + +dict_season = { + 1: "Зима", + 2: "Зима", + 12: "Зима", + 3: "Весна", + 4: "Весна", + 5: "Весна", + 6: "Лето", + 7: "Лето", + 8: "Лето", + 9: "Осень", + 10: "Осень", + 11: "Осень", +} +print(f"Время года - {dict_season.get(user_month)}") \ No newline at end of file diff --git a/lesson-2/lesson_2_task_4.py b/lesson-2/lesson_2_task_4.py new file mode 100644 index 0000000..275c9a1 --- /dev/null +++ b/lesson-2/lesson_2_task_4.py @@ -0,0 +1,6 @@ +#user_in = input('Введите произвольную строку: ') +user_in = 'мама мыла раму средствомдлямытья' +user_list = user_in.split() +for idx, el in enumerate(user_list, 1): + el = el[:10] + print(idx, el) diff --git a/lesson-2/lesson_2_task_5.py b/lesson-2/lesson_2_task_5.py new file mode 100644 index 0000000..f9e93d9 --- /dev/null +++ b/lesson-2/lesson_2_task_5.py @@ -0,0 +1,6 @@ +rating = [7, 5, 3, 2] +#user_rating = int(input('Введите свой рейтинг - натуральное число: ')) +user_rating = 4 +rating.append(user_rating) +rating.sort(reverse=True) +print(rating) diff --git a/lesson-2/lesson_2_task_6.py b/lesson-2/lesson_2_task_6.py new file mode 100644 index 0000000..2075a99 --- /dev/null +++ b/lesson-2/lesson_2_task_6.py @@ -0,0 +1,40 @@ +goods_list = [ + (1, {'Наименование': 'компьютер', 'Цена': '10000', 'Количество': '3', 'ед': 'шт'}), + (2, {'Наименование': 'ноутбук', 'Цена': '12000', 'Количество': '2', 'ед': 'шт'}), + (3, {'Наименование': 'принтер', 'Цена': '4000', 'Количество': '5', 'ед': 'шт'}) +] +# goods_list = [] +# goods_tuple = [] +# count_goods = int(input('Введите количество товаров, которые хотите внести в базу: ')) +# goods = { +# 'Наименование': None, +# 'Цена': None, +# 'Количество': None, +# 'ед': None, +# } +# el = 0 +# while el != count_goods: +# for i in goods: +# goods[i] = input(f'Введите {i}: ') +# goods.copy() +# goods_tuple.append(el + 1) +# goods_tuple.append(goods.copy()) +# goods_list.append(tuple(goods_tuple.copy())) +# goods_tuple.clear() +# el += 1 +# +# print(goods_list) + + +result = {} +for number, value in goods_list: + for k, v in value.items(): + try: + result[k] += [v] + except: + result[k] = [v] + +# Убираю дублирование "шт" + +result['ед'] = list(set(result.get('ед'))) +print(result) \ No newline at end of file diff --git a/lesson-3/Readme.txt b/lesson-3/Readme.txt new file mode 100644 index 0000000..7ddbeee --- /dev/null +++ b/lesson-3/Readme.txt @@ -0,0 +1,2 @@ +Во втором задании возможно не понял условие или оно простое. +После функции лямбда нужно 2 пробела? Pycharm при нажатии ctrl+alt+l делает 1 пробел. \ No newline at end of file diff --git a/lesson-3/leeson_3_task_1.py b/lesson-3/leeson_3_task_1.py new file mode 100644 index 0000000..2784a34 --- /dev/null +++ b/lesson-3/leeson_3_task_1.py @@ -0,0 +1,13 @@ +def division(num_1, num_2): + try: + return num_1 / num_2 + except ZeroDivisionError: + return ('Деление на 0 запрещено') + + +# num_1 = int(input('Введите первое число, которое хотите разделить: ')) +# num_2 = int(input('Введите второе число, на которое хотите разделить: ')) + +num_1 = 50 +num_2 = 20 +print(division(num_1, num_2)) diff --git a/lesson-3/lesson_3_task_2.py b/lesson-3/lesson_3_task_2.py new file mode 100644 index 0000000..6e5282e --- /dev/null +++ b/lesson-3/lesson_3_task_2.py @@ -0,0 +1,9 @@ +def user_list(**kwargs): + return kwargs + + +# Еще вариант с лямбда +user_list_2 = lambda **kwargs: kwargs + +print(user_list(first_name='Дмитрий', last_name='Лобанов', birth_year=1987, city='Podolsk', email='leget@list.ru')) +print(user_list_2(first_name='Дмитрий', last_name='Лобанов', birth_year=1987, city='Podolsk', email='leget@list.ru')) diff --git a/lesson-3/lesson_3_task_3.py b/lesson-3/lesson_3_task_3.py new file mode 100644 index 0000000..c50177f --- /dev/null +++ b/lesson-3/lesson_3_task_3.py @@ -0,0 +1,9 @@ +def sum_arg(num_1, num_2, num_3): + return sum([num_1, num_2, num_3]) - min(num_1, num_2, num_3) + + +# Вариант с лямбда функцией +arg_sum = lambda x, y, z: sum([x, y, z]) - min(x, y, z) + +print(arg_sum(500, 80, 100)) +print(sum_arg(500, 80, 100)) diff --git a/lesson-3/lesson_3_task_4.py b/lesson-3/lesson_3_task_4.py new file mode 100644 index 0000000..3da0a10 --- /dev/null +++ b/lesson-3/lesson_3_task_4.py @@ -0,0 +1,47 @@ +# Простое решение с помощью ** +exponentiation = lambda x, y: x ** y + +print(exponentiation(2, -5)) + + +# Решение без ** +def exponentiation_3(x, y): + if x == 0: + return 0 + elif y == 0: + return 1 + elif y == 1: + return x + elif y < 0: + positive_number_y = abs(y) + z = x + while positive_number_y > 1: + z *= x + positive_number_y -= 1 + return 1 / z + else: + z = x + while y > 1: + z *= x + y -= 1 + return z + + +print(exponentiation_3(2, -5)) + + +# Решение с помощью рекурсии +def exponentiation_2(x, y): + if x == 0: + return 0 + elif y == 0: + return 1 + elif y == 1: + return x + elif y < 0: + return 1 / (x * exponentiation_2(x, -y - 1)) + else: + return x * exponentiation_2(x, y - 1) + + +print(exponentiation_2(2, -5)) diff --git a/lesson-3/lesson_3_task_5.py b/lesson-3/lesson_3_task_5.py new file mode 100644 index 0000000..e7cd1e6 --- /dev/null +++ b/lesson-3/lesson_3_task_5.py @@ -0,0 +1,22 @@ +stop = None +summa = 0 +while True: + user_number = input("Введите числа через пробел, я посчитаю их сумму. Для выхода введите 'q': ") + number = user_number.split(' ') + list_number = [] + try: + for i in range(len(number)): + if number[i] != 'q': + list_number.append(float(number[i])) + elif number[i] == 'q': + stop = 1 + summa += sum(list_number) + except: + print('Вводите значения через 1 пробел') + continue + if stop: + print(f'Сумма введеных чисел равна {summa}') + print('Вы вышли из программы') + break + summa += sum(list_number) + print(summa) diff --git a/lesson-3/lesson_3_task_6.py b/lesson-3/lesson_3_task_6.py new file mode 100644 index 0000000..6d833e3 --- /dev/null +++ b/lesson-3/lesson_3_task_6.py @@ -0,0 +1,11 @@ +def int_func(text): + '''this function returns a string in which the first letter of all words is uppercase''' + new_text = text[0].upper() + text[1:] + for i in range(len(text)): + if text[i] == ' ': + new_text = new_text[:i + 1] + text[i + 1].upper() + text[i + 2:] + print(new_text) + + +int_func('text') +int_func('this text for testing the programm') From ec2056d09f0d1b0fbebbbe1d9bfdaba58314446e Mon Sep 17 00:00:00 2001 From: Dmitriy Lobanov Date: Sat, 15 Feb 2020 13:24:49 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=BE=D0=B5?= =?UTF-8?q?=20=D0=BF=D0=B5=D1=80=D0=B2=D0=BE=D0=B5=20=D0=B7=D0=B0=D0=B4?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lesson-4/lesson_4_task_1.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 lesson-4/lesson_4_task_1.py diff --git a/lesson-4/lesson_4_task_1.py b/lesson-4/lesson_4_task_1.py new file mode 100644 index 0000000..e69de29