From c3c3ef4f6f155af96a377587ba0a9c13bfd83e07 Mon Sep 17 00:00:00 2001 From: Margo Date: Sun, 10 Dec 2023 15:16:09 +0300 Subject: [PATCH 1/8] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F?= =?UTF-8?q?=20=D0=B4=D0=BE=D0=BC=D0=B0=D1=88=D0=BD=D1=8F=D1=8F=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1_if1.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/1_if1.py b/1_if1.py index be736084..bee8ac20 100644 --- a/1_if1.py +++ b/1_if1.py @@ -14,12 +14,22 @@ """ -def main(): - """ - Эта функция вызывается автоматически при запуске скрипта в консоли - В ней надо заменить pass на ваш код - """ - pass +def main(): + age_num = int(input("Введите свой возраст ")) + #age_num_error = "Введите положительное число" + if age_num >= 1 and age_num <=6: + print(f'Ваш возраст {age_num}. Вы должны быть в детском саду!') + if age_num >= 7 and age_num <=18: + print(f'Ваш возраст {age_num}. Вы должны учиться в школе!') + if age_num >= 19 and age_num <=23: + print(f'Ваш возраст {age_num}. Вы должны учиться в университете!') + if age_num >= 24 and age_num <=65: + print(f'Ваш возраст {age_num}. Вы должны работать!') + if age_num >= 66 and age_num <=100: + print(f'Ваш возраст {age_num}. Поздравляем, самое время отдохнуть!') + else: + raise ValueError("Введите число в промежутке от 1 до 100") + if __name__ == "__main__": - main() + main() \ No newline at end of file From fe831aa11dcc63099f9f6ccc4d6b99a26af9f25f Mon Sep 17 00:00:00 2001 From: Margo Date: Fri, 15 Dec 2023 02:19:10 +0300 Subject: [PATCH 2/8] =?UTF-8?q?=D0=94=D0=97=201=20=D0=B8=20=D0=BD=D0=B5?= =?UTF-8?q?=D0=BC=D0=BD=D0=BE=D0=B3=D0=BE=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1_if1.py | 5 ++--- 2_if2.py | 32 +++++++++++++++++++++++++------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/1_if1.py b/1_if1.py index bee8ac20..e5c3107b 100644 --- a/1_if1.py +++ b/1_if1.py @@ -17,7 +17,6 @@ def main(): age_num = int(input("Введите свой возраст ")) - #age_num_error = "Введите положительное число" if age_num >= 1 and age_num <=6: print(f'Ваш возраст {age_num}. Вы должны быть в детском саду!') if age_num >= 7 and age_num <=18: @@ -28,8 +27,8 @@ def main(): print(f'Ваш возраст {age_num}. Вы должны работать!') if age_num >= 66 and age_num <=100: print(f'Ваш возраст {age_num}. Поздравляем, самое время отдохнуть!') - else: - raise ValueError("Введите число в промежутке от 1 до 100") + #else: + #raise ValueError("Введите число в промежутке от 1 до 100") if __name__ == "__main__": main() \ No newline at end of file diff --git a/2_if2.py b/2_if2.py index 0f1644f3..6cfa2097 100644 --- a/2_if2.py +++ b/2_if2.py @@ -4,7 +4,7 @@ Условный оператор: Сравнение строк -* Написать функцию, которая принимает на вход две строки +* Написать функцию, которая принимает на вход две строки + * Проверить, является ли то, что передано функции, строками. Если нет - вернуть 0 * Если строки одинаковые, вернуть 1 @@ -15,12 +15,30 @@ """ + +string_first = input("Как дела? ") +string_second = input("Есть новогоднее настроение? ") + +print(type((string_first))) +print(type((string_second))) + +len_string_first = len(string_first) +len_string_second = len(string_second) + +print(len_string_first) +print(len_string_second) + def main(): - """ - Эта функция вызывается автоматически при запуске скрипта в консоли - В ней надо заменить pass на ваш код - """ - pass - + count = 1 + while count <= 4: + if type((string_first)) is not str and type((string_second)) is not str: + print(0) + if string_first == string_second: + print(1) + if string_first != string_second and len_string_first > len_string_second: + print(2) + if string_first != string_second and string_second == "learn": + print(3) + count += 1 if __name__ == "__main__": main() From 6d538ca865637f00d7eaffe4ba474d9a4cddbb22 Mon Sep 17 00:00:00 2001 From: Margo Date: Tue, 26 Dec 2023 07:29:47 +0300 Subject: [PATCH 3/8] =?UTF-8?q?4=20=D0=B7=D0=B0=D0=B4=D0=B0=D1=87=D0=B0,?= =?UTF-8?q?=203=20=D0=BD=D0=B5=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=B0,=205=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D0=BE=D0=B2=D0=B8=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1_if1.py | 4 ++-- 2_if2.py | 39 ++++++++++++++------------------------- 3_for.py | 19 ++++++++++++++----- 4_while1.py | 16 ++++++++++------ 5_while2.py | 13 +++++++------ 5 files changed, 47 insertions(+), 44 deletions(-) diff --git a/1_if1.py b/1_if1.py index e5c3107b..fae0d69a 100644 --- a/1_if1.py +++ b/1_if1.py @@ -27,8 +27,8 @@ def main(): print(f'Ваш возраст {age_num}. Вы должны работать!') if age_num >= 66 and age_num <=100: print(f'Ваш возраст {age_num}. Поздравляем, самое время отдохнуть!') - #else: - #raise ValueError("Введите число в промежутке от 1 до 100") + else: + raise ValueError("Введите число в промежутке от 1 до 100") if __name__ == "__main__": main() \ No newline at end of file diff --git a/2_if2.py b/2_if2.py index 6cfa2097..4b3113be 100644 --- a/2_if2.py +++ b/2_if2.py @@ -14,31 +14,20 @@ и выводя на экран результаты """ +def main(a, b): + if type(a) is not str and type(b) is not str: + print(0) + if a == b: + print(1) + if len(a) != len(b) and len(a) > len(b): + print(2) + if a != b and b == "learn": + print(3) + +main("450","10") +main(5, 7) +main("дада","нетнет") +main(0,-1) - -string_first = input("Как дела? ") -string_second = input("Есть новогоднее настроение? ") - -print(type((string_first))) -print(type((string_second))) - -len_string_first = len(string_first) -len_string_second = len(string_second) - -print(len_string_first) -print(len_string_second) - -def main(): - count = 1 - while count <= 4: - if type((string_first)) is not str and type((string_second)) is not str: - print(0) - if string_first == string_second: - print(1) - if string_first != string_second and len_string_first > len_string_second: - print(2) - if string_first != string_second and string_second == "learn": - print(3) - count += 1 if __name__ == "__main__": main() diff --git a/3_for.py b/3_for.py index 5ca9f504..ebb56ffc 100644 --- a/3_for.py +++ b/3_for.py @@ -16,12 +16,21 @@ * Посчитать и вывести среднее количество продаж всех товаров """ +from pprint import pprint + +sales = [ + {'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]}, +] + +for product in sales: + sum(sales['items_sold']) + #sum(sales{'items_sold'}) + def main(): - """ - Эта функция вызывается автоматически при запуске скрипта в консоли - В ней надо заменить pass на ваш код - """ - pass + + if __name__ == "__main__": main() diff --git a/4_while1.py b/4_while1.py index b5791517..b690f835 100644 --- a/4_while1.py +++ b/4_while1.py @@ -11,11 +11,15 @@ def hello_user(): - """ - Замените pass на ваш код - """ - pass - - + + while True: + check_status = input("Как дела? ") + if check_status == "Хорошо": + print("Отлично!") + break + else: + print("Тогда надо пойти покушать") + + if __name__ == "__main__": hello_user() diff --git a/5_while2.py b/5_while2.py index 49012dfd..78bbc23b 100644 --- a/5_while2.py +++ b/5_while2.py @@ -15,13 +15,14 @@ """ -questions_and_answers = {} +questions_and_answers = [{"Как дела?": "Хорошо!", "Что делаешь?": "Программирую", "Ты молодец?": "Да"}] def ask_user(answers_dict): - """ - Замените pass на ваш код - """ - pass - + answers_dict = input("Введите вопрос: ") + if answers_dict in questions_and_answers: + print(answers_dict) + else: + print("Тогда надо пойти покушать") +#answers_dict if __name__ == "__main__": ask_user(questions_and_answers) From a73e57b9c3665e427d31ea38d94aa2bae56dbdf8 Mon Sep 17 00:00:00 2001 From: Davydova_Ma Date: Thu, 4 Jan 2024 14:57:58 +0300 Subject: [PATCH 4/8] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=B4=D0=B0=D1=87=D0=B0=D1=87=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3_for.py | 5 ++--- 5_while2.py | 17 +++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/3_for.py b/3_for.py index ebb56ffc..d7f17cbb 100644 --- a/3_for.py +++ b/3_for.py @@ -24,9 +24,8 @@ {'product': 'Samsung Galaxy 21', 'items_sold': [343, 390, 238, 437, 214, 494, 441, 518, 212, 288, 272, 247]}, ] -for product in sales: - sum(sales['items_sold']) - #sum(sales{'items_sold'}) +for calc_sales in sales: + sum(sales['items_sold']) def main(): diff --git a/5_while2.py b/5_while2.py index 78bbc23b..1b086cd3 100644 --- a/5_while2.py +++ b/5_while2.py @@ -15,14 +15,15 @@ """ -questions_and_answers = [{"Как дела?": "Хорошо!", "Что делаешь?": "Программирую", "Ты молодец?": "Да"}] +questions_and_answers = { + "Как дела?": "Хорошо!", + "Что делаешь?": "Программирую", + "Кто молодец?": "Ты" + } -def ask_user(answers_dict): - answers_dict = input("Введите вопрос: ") - if answers_dict in questions_and_answers: - print(answers_dict) - else: - print("Тогда надо пойти покушать") -#answers_dict +def ask_user(question): + question = input("Введите вопрос: ") + print(questions_and_answers.get(question)) + if __name__ == "__main__": ask_user(questions_and_answers) From d06fbe86da50e5ff353ab3cf815927cf286043be Mon Sep 17 00:00:00 2001 From: Davydova_Ma Date: Sun, 7 Jan 2024 17:58:28 +0300 Subject: [PATCH 5/8] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D1=87=D0=B0=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3_for.py | 12 +++++------- 5_while2.py | 10 ++++++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/3_for.py b/3_for.py index d7f17cbb..909bd15e 100644 --- a/3_for.py +++ b/3_for.py @@ -24,12 +24,10 @@ {'product': 'Samsung Galaxy 21', 'items_sold': [343, 390, 238, 437, 214, 494, 441, 518, 212, 288, 272, 247]}, ] -for calc_sales in sales: - sum(sales['items_sold']) - def main(): - - - + for total_sales_sum in sales: + total_sales_sum = sum(sales[0]['items_sold']) + print("Количество продаж ", sales[0]['product'], " = ", total_sales_sum) + if __name__ == "__main__": - main() + main() \ No newline at end of file diff --git a/5_while2.py b/5_while2.py index 1b086cd3..509dd491 100644 --- a/5_while2.py +++ b/5_while2.py @@ -22,8 +22,14 @@ } def ask_user(question): - question = input("Введите вопрос: ") - print(questions_and_answers.get(question)) + x = 1 + while x <= 3: + question = input("Введите вопрос: ") + print(questions_and_answers.get(question)) + if question == "Нет": + print("Завершение программы") + break + x += 1 if __name__ == "__main__": ask_user(questions_and_answers) From cb65eaad32be8282fa74eda209a0de261d81b77c Mon Sep 17 00:00:00 2001 From: Davydova_Ma Date: Sun, 14 Jan 2024 02:44:10 +0300 Subject: [PATCH 6/8] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D1=87=D0=B0=206=20?= =?UTF-8?q?=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=B0.=20=D0=9F=D0=BE=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=B4=D0=B0=D1=87=D0=B5=203=20=D0=B2=D0=BE=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D1=81=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3_for.py | 31 +++++++++++++++++++++++++++---- 3_for_2.py | 21 +++++++++++++++++++++ 6_exception1.py | 18 +++++++++++++----- 7_exception2.py | 26 ++++++++++++++++++++------ 4 files changed, 81 insertions(+), 15 deletions(-) create mode 100644 3_for_2.py diff --git a/3_for.py b/3_for.py index 909bd15e..29e040dc 100644 --- a/3_for.py +++ b/3_for.py @@ -17,6 +17,7 @@ """ from pprint import pprint +from statistics import mean sales = [ {'product': 'iPhone 12', 'items_sold': [363, 500, 224, 358, 480, 476, 470, 216, 270, 388, 312, 186]}, @@ -25,9 +26,31 @@ ] def main(): - for total_sales_sum in sales: - total_sales_sum = sum(sales[0]['items_sold']) - print("Количество продаж ", sales[0]['product'], " = ", total_sales_sum) + for count_sales in sales: + sales_sum = sum(count_sales.get('items_sold')) + average_value = mean(count_sales.get('items_sold')) + total_sales_sum = sum(int(str.join(count_sales['items_sold']))) + print(f'Суммарное количество продаж {count_sales.get('product')}: ', sales_sum) + print(f'Среднее количество продаж {count_sales.get('product')}: ', average_value) + print(total_sales_sum) + if __name__ == "__main__": - main() \ No newline at end of file + main() + +classes = [ + {'name': '3А', 'scores': [3,4,4,5,2]}, + {'name': '3Б', 'scores': [5,5,3,2,2]}, + {'name': '3В', 'scores': [4,5,3,5,4]}, +] + +def count_average(students_scores): + scores_sum = 0 + for score in students_scores: + scores_sum += score + scores_avg = scores_sum / len(students_scores) + return scores_avg + +for one_class in classes: + class_score_avg = count_average(one_class['scores']) + print(f"Средняя оценка для класса {one_class['name']}: {class_score_avg}") \ No newline at end of file diff --git a/3_for_2.py b/3_for_2.py new file mode 100644 index 00000000..66576a4d --- /dev/null +++ b/3_for_2.py @@ -0,0 +1,21 @@ +sales = [ + {'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]}, +] + +def count_sales(sale_list): #функция count_sales с аргументом sale_list + sales_sum = 0 #знчение переменной sales_sum равно нолю + for count in sale_list: #для переменной count в sale_list + sales_sum += count #прибавляй к значению переменной sales_sum значение переменной count и записывай его в sales_sum + return sales_sum / len(sale_list) #возвращай значение sales_sum деленное на длину списка sale_list + +school_avg_sum = 0 +for one_item in sales:#для переменной one_item в sales + total_sales_sum = count_sales(one_item['items_sold']) + print(f"Средняя оценка для продукта {one_item['product']}: {total_sales_sum}") + school_avg_sum += total_sales_sum + print(f"Средняя оценка для школы: {school_avg_sum / len(sales)}") + +if __name__ == "__count_sales__": + count_sales() \ No newline at end of file diff --git a/6_exception1.py b/6_exception1.py index 3ea9d054..a6220c83 100644 --- a/6_exception1.py +++ b/6_exception1.py @@ -11,10 +11,18 @@ """ def hello_user(): - """ - Замените pass на ваш код - """ - pass + try: + while True: + check_status = input("Как дела? ") + if check_status == "Хорошо": + print("Отлично!") + break + else: + print("Для остановки программы нажмите Ctrl+C") + + except KeyboardInterrupt: + print('Пока!') + if __name__ == "__main__": - hello_user() + hello_user() \ No newline at end of file diff --git a/7_exception2.py b/7_exception2.py index d4bd8a39..0bebd723 100644 --- a/7_exception2.py +++ b/7_exception2.py @@ -1,4 +1,4 @@ -""" +breakbreak""" Домашнее задание №1 @@ -13,11 +13,25 @@ """ -def discounted(price, discount, max_discount=20) - """ - Замените pass на ваш код - """ - pass +year = input('Как вас зовут? ') +real_age = 2021 - int(year) +print(f'Привет, Ваш возраст: {real_age}') + +def discounted(price, discount, max_discount=20): + price = abs(price) + discount = abs(discount) + max_discount = abs(max_discount) + if max_discount >= 100: + raise ValueError("Максимальная скидка не должна быть больше 100") + if discount >= max_discount: + price_with_discount = price + else: + price_with_discount = price - (price * discount /100) + return price_with_discount + +print(discounted(100, 5)) +print(discounted(100, 50)) +print(discounted(100, 50, max_discount=60)) if __name__ == "__main__": print(discounted(100, 2)) From 94e9042fd860ad03e112d49309b7007824cbd3b4 Mon Sep 17 00:00:00 2001 From: Davydova_Ma Date: Sun, 14 Jan 2024 02:51:55 +0300 Subject: [PATCH 7/8] 3_for_2.py changed --- 3_for.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/3_for.py b/3_for.py index 29e040dc..5a40bea4 100644 --- a/3_for.py +++ b/3_for.py @@ -38,19 +38,3 @@ def main(): if __name__ == "__main__": main() -classes = [ - {'name': '3А', 'scores': [3,4,4,5,2]}, - {'name': '3Б', 'scores': [5,5,3,2,2]}, - {'name': '3В', 'scores': [4,5,3,5,4]}, -] - -def count_average(students_scores): - scores_sum = 0 - for score in students_scores: - scores_sum += score - scores_avg = scores_sum / len(students_scores) - return scores_avg - -for one_class in classes: - class_score_avg = count_average(one_class['scores']) - print(f"Средняя оценка для класса {one_class['name']}: {class_score_avg}") \ No newline at end of file From 2cadb6781fb518b5b37ea5d28be9d4ddfd576d50 Mon Sep 17 00:00:00 2001 From: Davydova_Ma Date: Sun, 14 Jan 2024 04:46:13 +0300 Subject: [PATCH 8/8] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D1=87=D0=B0=207=20?= =?UTF-8?q?=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 7_exception2.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/7_exception2.py b/7_exception2.py index 0bebd723..bdb04ea9 100644 --- a/7_exception2.py +++ b/7_exception2.py @@ -1,4 +1,4 @@ -breakbreak""" +""" Домашнее задание №1 @@ -12,15 +12,11 @@ ValueError и TypeError, если приведение типов не сработало. """ - -year = input('Как вас зовут? ') -real_age = 2021 - int(year) -print(f'Привет, Ваш возраст: {real_age}') - def discounted(price, discount, max_discount=20): - price = abs(price) - discount = abs(discount) - max_discount = abs(max_discount) + try: + price = float(abs(price)) + discount = float(abs(discount)) + max_discount = int(abs(max_discount)) if max_discount >= 100: raise ValueError("Максимальная скидка не должна быть больше 100") if discount >= max_discount: @@ -28,10 +24,10 @@ def discounted(price, discount, max_discount=20): else: price_with_discount = price - (price * discount /100) return price_with_discount + + except (ValueError, TypeError): + print('Вы ввели неверный тип данных') -print(discounted(100, 5)) -print(discounted(100, 50)) -print(discounted(100, 50, max_discount=60)) if __name__ == "__main__": print(discounted(100, 2))