From 9d3f5d553ca8c89e508b9caf5830c1bfc4a62436 Mon Sep 17 00:00:00 2001 From: Olga Glazunova Date: Wed, 27 Nov 2024 17:05:48 +0500 Subject: [PATCH 1/9] =?UTF-8?q?=D0=92=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B8?= =?UTF-8?q?=D0=BB=D0=B0=20=D0=BF=D0=B5=D1=80=D0=B2=D0=BE=D0=B5=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1_if1.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/1_if1.py b/1_if1.py index be736084..c5d606e9 100644 --- a/1_if1.py +++ b/1_if1.py @@ -14,12 +14,28 @@ """ -def main(): - """ +def main(age): + if age >= 2 and age < 7: + return "Детский сад" + elif age >= 7 and age < 18: + return "Школа" + elif age >= 18 and age < 23: + return "вуз" + elif age >= 23 and age < 60: + return "Работа" + else: + return "Старый или малый)" + +age_in = input("Введите ваш возраст: ") +age = int(age_in) +activity = main(age) +print(f"Ваше занятие по возрасту {activity}") +input () +""" Эта функция вызывается автоматически при запуске скрипта в консоли В ней надо заменить pass на ваш код """ - pass + # pass -if __name__ == "__main__": - main() +#if __name__ == "__main__": + # main() From 43853099330b9dc81dcd4bee59e8eb42c40e1467 Mon Sep 17 00:00:00 2001 From: Olga Glazunova Date: Fri, 29 Nov 2024 18:36:26 +0500 Subject: [PATCH 2/9] =?UTF-8?q?=D0=92=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=94=D0=97=20=D1=81=201=20=D0=BF=D0=BE=207?= =?UTF-8?q?=D0=B5.=208=20=D0=BF=D0=BE=D0=BA=D0=B0=20=D0=B2=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D1=86=D0=B5=D1=81=D1=81=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2_if2.py | 32 ++++++++++++++++++++++++-------- 3_for.py | 42 +++++++++++++++++++++++++++++++++--------- 4_while1.py | 20 +++++++++++++------- 5_while2.py | 28 +++++++++++++++++++++++----- 6_exception1.py | 25 +++++++++++++++++++------ 7_exception2.py | 37 +++++++++++++++++++++++++++---------- 6 files changed, 139 insertions(+), 45 deletions(-) diff --git a/2_if2.py b/2_if2.py index 0f1644f3..82f4e5b3 100644 --- a/2_if2.py +++ b/2_if2.py @@ -15,12 +15,28 @@ """ -def main(): - """ - Эта функция вызывается автоматически при запуске скрипта в консоли - В ней надо заменить pass на ваш код - """ - pass +def main(str1,str2): + if not isinstance(str1, str) or not isinstance(str2, str): + return 0 + if str1 == str2: + return 1 + if len(str1) > len(str2): + return 2 + if str1 != str2 and str2 == "learn": + return 3 + +print(main ("text","123")) +print(main("text","text")) +print(main("texttexttext", "text")) +print(main("text","learn")) + +input() + + # """ + # Эта функция вызывается автоматически при запуске скрипта в консоли + # В ней надо заменить pass на ваш код + # """ +# pass -if __name__ == "__main__": - main() +#if __name__ == "__main__": + # main() diff --git a/3_for.py b/3_for.py index 5ca9f504..5e1ffa95 100644 --- a/3_for.py +++ b/3_for.py @@ -5,7 +5,7 @@ Цикл for: Продажи товаров * Дан список словарей с данными по колличеству проданных телефонов - [ + [ {'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]}, @@ -15,13 +15,37 @@ * Посчитать и вывести суммарное количество продаж всех товаров * Посчитать и вывести среднее количество продаж всех товаров """ +data = [ + {'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 main(data): + all_sales = 0 + all_products = len(data) + for phone in data: + product = phone['product'] + sales = phone['items_sold'] + total_sales = sum(sales) + avg_sales = round(total_sales / len(sales), 2) + + print(f'телефон: {product} суммарное колиичество продаж: {total_sales}, среднее количество продаж: {avg_sales}') + + all_sales += total_sales + + avg_all_sales = round(all_sales / all_products, 2) + print(f'суммарное количество продаж {all_sales}') + print(f'среднее количество продаж {avg_all_sales}') + +main(data) -def main(): - """ - Эта функция вызывается автоматически при запуске скрипта в консоли - В ней надо заменить pass на ваш код - """ - pass +input() + + #""" + #Эта функция вызывается автоматически при запуске скрипта в консоли + #В ней надо заменить pass на ваш код + #""" + #pass -if __name__ == "__main__": - main() +#if __name__ == "__main__": + #main() diff --git a/4_while1.py b/4_while1.py index b5791517..d6efe713 100644 --- a/4_while1.py +++ b/4_while1.py @@ -11,11 +11,17 @@ def hello_user(): - """ - Замените pass на ваш код - """ - pass +# """ +# Замените pass на ваш код +# """ + while True: + ask = input('Как дела? ') + if ask == ('хорошо'): + break + else: + print('Как дела? ') +hello_user() - -if __name__ == "__main__": - hello_user() +input() +#if __name__ == "__main__": +# hello_user() diff --git a/5_while2.py b/5_while2.py index 49012dfd..4beba4f1 100644 --- a/5_while2.py +++ b/5_while2.py @@ -15,13 +15,31 @@ """ -questions_and_answers = {} +questions_and_answers = { + "как дела?": "хорошо", + "Чем занимаешься?": "Программирую", + "Как тебя зовут?": "Оля", + "Сколько тебе лет?": "38", + "Ты умеешь программировать?": "нет, но хочу научиться", + "какой язык ты изучаешь?": "python" + } -def ask_user(answers_dict): +def ask_user(): """ Замените pass на ваш код """ - pass -if __name__ == "__main__": - ask_user(questions_and_answers) + question = input('Введите вопрос: ') + answer = questions_and_answers.get(question) + if question in questions_and_answers: + print(answer) + else: + print("я не знаю") + +ask_user() + +input() + + +#if __name__ == "__main__": +# ask_user(questions_and_answers) diff --git a/6_exception1.py b/6_exception1.py index 3ea9d054..ed803c82 100644 --- a/6_exception1.py +++ b/6_exception1.py @@ -11,10 +11,23 @@ """ def hello_user(): - """ - Замените pass на ваш код - """ - pass +# """ +# Замените pass на ваш код +# """ + try: + while True: + ask = input('Как дела? ') + if ask == ('хорошо'): + break + else: + print('Как дела? ') + except KeyboardInterrupt: + print('Пока!') + -if __name__ == "__main__": - hello_user() +hello_user() + +input() + +#if __name__ == "__main__": +# hello_user() diff --git a/7_exception2.py b/7_exception2.py index d4bd8a39..02062ba2 100644 --- a/7_exception2.py +++ b/7_exception2.py @@ -13,16 +13,33 @@ """ -def discounted(price, discount, max_discount=20) +def discounted(price, discount, max_discount=20): """ Замените pass на ваш код """ - pass - -if __name__ == "__main__": - print(discounted(100, 2)) - print(discounted(100, "3")) - print(discounted("100", "4.5")) - print(discounted("five", 5)) - print(discounted("сто", "десять")) - print(discounted(100.0, 5, "10")) + try: + price = abs(price) + price = float(price) + discount = abs(discount) + discount = float(discount) + max_discount = abs(max_discount) + max_discount = int(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 + except(ValueError, TypeError): + print("Не сработало приведение типов") + +input() + +#if __name__ == "__main__": +print(discounted(100, 2)) +print(discounted(100, "3")) +print(discounted("100", "4.5")) +print(discounted("five", 5)) +print(discounted("сто", "десять")) +print(discounted(100.0, 5, "10")) From 71d8d5956af2a48ad0b417120716ac265eb51508 Mon Sep 17 00:00:00 2001 From: Olga Glazunova Date: Sat, 30 Nov 2024 12:56:17 +0500 Subject: [PATCH 3/9] =?UTF-8?q?ephem=5Fbot=20=D0=B2=D1=8B=D0=B2=D0=BE?= =?UTF-8?q?=D0=B4=D0=B8=D1=82=20=D0=B2=20=D0=BA=D0=B0=D0=BA=D0=BE=D0=BC=20?= =?UTF-8?q?=D1=81=D0=BE=D0=B7=D0=B2=D0=B5=D0=B7=D0=B4=D0=B8=D0=B8=20=D0=BD?= =?UTF-8?q?=D0=B0=D1=85=D0=BE=D0=B4=D0=B8=D1=82=D1=81=D1=8F=20=D0=BF=D0=BB?= =?UTF-8?q?=D0=B0=D0=BD=D0=B5=D1=82=D0=B0,=20=D0=BA=D1=80=D0=BE=D0=BC?= =?UTF-8?q?=D0=B5=20=D0=B7=D0=B5=D0=BC=D0=BB=D0=B8.=20=D0=BD=D1=83=D0=B6?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=B4=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0=D1=82=D1=8C?= =?UTF-8?q?=20=D0=B7=D0=B5=D0=BC=D0=BB=D1=8E,=20=D1=83=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D1=82=D1=8C=20=D1=87=D1=83=D0=B2=D1=81=D1=82=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D0=BA=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B3=D0=B8=D1=81=D1=82=D1=80=D1=83,=20=D1=87?= =?UTF-8?q?=D1=82=D0=BE-=D1=82=D0=BE=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0?= =?UTF-8?q?=D1=82=D1=8C=20=D1=81=20=D0=B4=D0=B0=D1=82=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 8_ephem_bot.py | 105 ++++++++++++++++++++++++++++--------------------- 1 file changed, 61 insertions(+), 44 deletions(-) diff --git a/8_ephem_bot.py b/8_ephem_bot.py index 1cf9ea19..4fec063a 100644 --- a/8_ephem_bot.py +++ b/8_ephem_bot.py @@ -1,57 +1,74 @@ -""" -Домашнее задание №1 - -Использование библиотек: ephem - -* Установите модуль ephem -* Добавьте в бота команду /planet, которая будет принимать на вход - название планеты на английском, например /planet Mars -* В функции-обработчике команды из update.message.text получите - название планеты (подсказка: используйте .split()) -* При помощи условного оператора if и ephem.constellation научите - бота отвечать, в каком созвездии сегодня находится планета. - -""" -import logging - from telegram.ext import Updater, CommandHandler, MessageHandler, Filters -logging.basicConfig(format='%(name)s - %(levelname)s - %(message)s', - level=logging.INFO, - filename='bot.log') - - -PROXY = { - 'proxy_url': 'socks5://t1.learn.python.ru:1080', - 'urllib3_proxy_kwargs': { - 'username': 'learn', - 'password': 'python' - } -} - - def greet_user(update, context): - text = 'Вызван /start' - print(text) - update.message.reply_text(text) - - -def talk_to_me(update, context): - user_text = update.message.text - print(user_text) - update.message.reply_text(text) + print("Вызван /start") + update.message.reply_text("Привет!") + +#def talk_to_me(update, context): +# text = update.message.text +# print(text) +# update.message.reply_text(text) + +def planets(update, context): + import ephem + print("Вызвана функция planets") + +# planet = update.message.text +# planet = ephem.Mars('2024/11/29') +# update.message.reply_text("Планета {planet}") +# print(planet) +# const = ephem.constellation(planet) +# print(const) +# update.message.reply_text(const) + try: +# planet = ephem.Mars('2024/11/29') + planet = update.message.text + planet_name = planet.split() + print(planet_name) + name = planet_name[1] + Mars = ephem.Mars("2024/11/30") +# Earth = ephem.Earth("2024/11/30") + Uranus = ephem.Uranus("2024/11/30") + Jupiter = ephem.Jupiter("2024/11/30") + Neptune = ephem.Neptune("2024/11/30") + Venus = ephem.Venus("2024/11/30") + Pluto = ephem.Pluto("2024/11/30") + Mercury = ephem.Mercury("2024/11/30") + if name == "Mars": + const = ephem.constellation(Mars) + elif name == "Jupiter": + const = ephem.constellation(Jupiter) + elif name == "Uranus": + const = ephem.constellation(Uranus) + elif name == "Neptune": + const = ephem.constellation(Neptune) + elif name == "Venus": + const = ephem.constellation(Venus) + elif name == "Pluto": + const = ephem.constellation(Pluto) + elif name == "Mercury": + const = ephem.constellation(Mercury) + else: +# const = ephem.constellation(Earth) + print("Не знаю такую планету") + print(const) + update.message.reply_text(const) + except Exception as e: + print(e) def main(): - mybot = Updater("КЛЮЧ, КОТОРЫЙ НАМ ВЫДАЛ BotFather", request_kwargs=PROXY, use_context=True) + mybot = Updater("7834567751:AAGfqPXRFL3-GDBOH0IcORp7DSIzyJ_W-Jw", use_context = True) + dp = mybot.dispatcher dp.add_handler(CommandHandler("start", greet_user)) - dp.add_handler(MessageHandler(Filters.text, talk_to_me)) - + dp.add_handler(CommandHandler("planet", planets)) +# dp.add_handler(MessageHandler(Filters.text, talk_to_me)) + dp.add_handler(MessageHandler(Filters.text, planets)) mybot.start_polling() mybot.idle() +main() -if __name__ == "__main__": - main() +input() \ No newline at end of file From 8b6721f3ad6290f27c3d8bbc0cb2b14d44f316fe Mon Sep 17 00:00:00 2001 From: Olga Glazunova Date: Sun, 1 Dec 2024 17:46:17 +0500 Subject: [PATCH 4/9] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=201.=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B8=D0=BC=D0=B5=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BB=D0=B0=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8?= =?UTF-8?q?=D1=8E,=20=D1=83=D0=B1=D1=80=D0=B0=D0=BB=D0=B0=20=D0=BB=D0=B8?= =?UTF-8?q?=D1=88=D0=BD=D0=B8=D0=B5=20=D1=83=D1=81=D0=BB=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1_if1.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/1_if1.py b/1_if1.py index c5d606e9..89345d6c 100644 --- a/1_if1.py +++ b/1_if1.py @@ -14,21 +14,21 @@ """ -def main(age): +def get_activity(age): if age >= 2 and age < 7: return "Детский сад" - elif age >= 7 and age < 18: + elif age < 18: return "Школа" - elif age >= 18 and age < 23: + elif age < 23: return "вуз" - elif age >= 23 and age < 60: + elif age < 60: return "Работа" else: return "Старый или малый)" age_in = input("Введите ваш возраст: ") age = int(age_in) -activity = main(age) +activity = get_activity(age) print(f"Ваше занятие по возрасту {activity}") input () """ From f4bdc48239877113c7d1905621b32c02fb25cd57 Mon Sep 17 00:00:00 2001 From: Olga Glazunova Date: Sun, 1 Dec 2024 18:26:00 +0500 Subject: [PATCH 5/9] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=204.=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B8=D0=BC=D0=B5=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BB=D0=B0=20ask=20=D0=B2=20how=5Fare=5Fyou?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 4_while1.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/4_while1.py b/4_while1.py index d6efe713..1b1b9128 100644 --- a/4_while1.py +++ b/4_while1.py @@ -15,8 +15,8 @@ def hello_user(): # Замените pass на ваш код # """ while True: - ask = input('Как дела? ') - if ask == ('хорошо'): + how_are_you = input('Как дела? ') + if how_are_you == ('хорошо'): break else: print('Как дела? ') From 4de17a5ce2747ad60f1b7bba83a4c26a4a7b1a1d Mon Sep 17 00:00:00 2001 From: Olga Glazunova Date: Sun, 1 Dec 2024 18:48:10 +0500 Subject: [PATCH 6/9] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=205.=20=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BB=D0=B0=20=D1=87=D0=B5=D1=80=D0=B5=D0=B7=20.get(...)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 5_while2.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/5_while2.py b/5_while2.py index 4beba4f1..a1bede6b 100644 --- a/5_while2.py +++ b/5_while2.py @@ -30,11 +30,14 @@ def ask_user(): """ question = input('Введите вопрос: ') - answer = questions_and_answers.get(question) - if question in questions_and_answers: - print(answer) - else: - print("я не знаю") + answer = "Другой вопрос" + answer = questions_and_answers.get(question, answer) + print(answer) +# answer = questions_and_answers.get(question) +# if question in questions_and_answers: +# print(answer) +# else: +# print("я не знаю") ask_user() From 4cc817c1e0ef86f5f47ce9a025e051a6a20d575b Mon Sep 17 00:00:00 2001 From: Olga Glazunova Date: Tue, 3 Dec 2024 08:40:13 +0500 Subject: [PATCH 7/9] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D0=B0=20=D1=83=D1=81=D0=BB=D0=BE=D0=B2=D0=B8=D1=8F,=20?= =?UTF-8?q?=D1=87=D1=82=D0=BE=D0=B1=D1=8B=20=D0=B2=D0=BE=D0=B7=D1=80=D0=B0?= =?UTF-8?q?=D1=81=D1=82=20<2=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=B0=D1=82?= =?UTF-8?q?=D1=8B=D0=B2=D0=B0=D0=BB=D1=81=D1=8F=20=D0=BA=D0=BE=D1=80=D1=80?= =?UTF-8?q?=D0=B5=D0=BA=D1=82=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1_if1.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/1_if1.py b/1_if1.py index 89345d6c..904bddbc 100644 --- a/1_if1.py +++ b/1_if1.py @@ -17,11 +17,11 @@ def get_activity(age): if age >= 2 and age < 7: return "Детский сад" - elif age < 18: + elif age >=7 and age < 18: return "Школа" - elif age < 23: + elif age >=18 and age < 23: return "вуз" - elif age < 60: + elif age >=23 and age < 60: return "Работа" else: return "Старый или малый)" From e8dc5bc3f31f5563a86c6d0287a2f6a1e8813422 Mon Sep 17 00:00:00 2001 From: Olga Glazunova Date: Tue, 3 Dec 2024 08:41:48 +0500 Subject: [PATCH 8/9] =?UTF-8?q?=D0=98=D0=BC=D0=BF=D0=BE=D1=80=D1=82=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BB=D0=B0=20=D0=BC=D0=BE=D0=B4=D1=83?= =?UTF-8?q?=D0=BB=D1=8C=20datetime,=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D0=B0=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD?= =?UTF-8?q?=D1=83=D1=8E=20today,=20=D1=87=D1=82=D0=BE=D0=B1=D1=8B=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BB=D0=BE=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=BB?= =?UTF-8?q?=D0=B0=D0=BD=D0=B5=D1=82=20=D0=B1=D1=80=D0=B0=D0=BB=D0=BE=D1=81?= =?UTF-8?q?=D1=8C=20=D0=BD=D0=B0=20=D1=82=D0=B5=D0=BA=D1=83=D1=89=D1=83?= =?UTF-8?q?=D1=8E=20=D0=B4=D0=B0=D1=82=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 8_ephem_bot.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/8_ephem_bot.py b/8_ephem_bot.py index 4fec063a..fe637d9a 100644 --- a/8_ephem_bot.py +++ b/8_ephem_bot.py @@ -1,4 +1,6 @@ from telegram.ext import Updater, CommandHandler, MessageHandler, Filters +from datetime import date + def greet_user(update, context): print("Вызван /start") @@ -12,7 +14,9 @@ def greet_user(update, context): def planets(update, context): import ephem print("Вызвана функция planets") - + + import datetime + today = date.today() # planet = update.message.text # planet = ephem.Mars('2024/11/29') # update.message.reply_text("Планета {planet}") @@ -26,14 +30,15 @@ def planets(update, context): planet_name = planet.split() print(planet_name) name = planet_name[1] - Mars = ephem.Mars("2024/11/30") + + Mars = ephem.Mars(today) # Earth = ephem.Earth("2024/11/30") - Uranus = ephem.Uranus("2024/11/30") - Jupiter = ephem.Jupiter("2024/11/30") - Neptune = ephem.Neptune("2024/11/30") - Venus = ephem.Venus("2024/11/30") - Pluto = ephem.Pluto("2024/11/30") - Mercury = ephem.Mercury("2024/11/30") + Uranus = ephem.Uranus(today) + Jupiter = ephem.Jupiter(today) + Neptune = ephem.Neptune(today) + Venus = ephem.Venus(today) + Pluto = ephem.Pluto(today) + Mercury = ephem.Mercury(today) if name == "Mars": const = ephem.constellation(Mars) elif name == "Jupiter": From 51535d8357cfd71c1e64c3069104f3a209cabae1 Mon Sep 17 00:00:00 2001 From: Olga Glazunova Date: Tue, 3 Dec 2024 12:08:19 +0500 Subject: [PATCH 9/9] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=BC=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D0=B8=D0=BB=D0=B0=20except?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 7_exception2.py | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/7_exception2.py b/7_exception2.py index 02062ba2..8c88a116 100644 --- a/7_exception2.py +++ b/7_exception2.py @@ -18,28 +18,36 @@ def discounted(price, discount, max_discount=20): Замените pass на ваш код """ try: - price = abs(price) - price = float(price) - discount = abs(discount) - discount = float(discount) - max_discount = abs(max_discount) - max_discount = int(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 - except(ValueError, TypeError): - print("Не сработало приведение типов") + price = abs(float(price)) + # price = float(price) + discount = abs(float(discount)) + # discount = float(discount) + max_discount = abs(int(max_discount)) + # max_discount = int(max_discount) + except(TypeError): + raise TypeError("Не сработало приведение типов") + except(ValueError): + raise ValueError("Не удалось привести аргуметы к числам") + + 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 + + input() #if __name__ == "__main__": + print(discounted(100, 2)) print(discounted(100, "3")) print(discounted("100", "4.5")) print(discounted("five", 5)) print(discounted("сто", "десять")) print(discounted(100.0, 5, "10")) +print(discounted(100, 200)) +print(discounted(100, 200, 200)) \ No newline at end of file