-
Notifications
You must be signed in to change notification settings - Fork 470
Homework #113
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
base: master
Are you sure you want to change the base?
Homework #113
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,15 +10,31 @@ | |
| * Первые два нужно приводить к вещественному числу при помощи float(), | ||
| а третий - к целому при помощи int() и перехватывать исключения | ||
| ValueError и TypeError, если приведение типов не сработало. | ||
|
|
||
| """ | ||
|
|
||
| def discounted(price, discount, max_discount=20) | ||
| def discounted(price, discount, max_discount=20): | ||
| """ | ||
| Замените pass на ваш код | ||
| """ | ||
| pass | ||
|
|
||
| try: | ||
| price = abs(float(price)) | ||
| discount = abs(float(discount)) | ||
| max_discount = abs(int(max_discount)) | ||
| except TypeError: | ||
| print('Ошибка, передан не верный тип!') | ||
| return | ||
| except ValueError: | ||
| print('Ошибка, переданы не верные данные!') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| return | ||
|
|
||
| if max_discount >= 100: | ||
| raise ValueError('Слишком большая максимальная скидка') | ||
| if discount >= max_discount: | ||
| return price | ||
| else: | ||
| return price - (price * discount / 100) | ||
|
|
||
| if __name__ == "__main__": | ||
| print(discounted(100, 2)) | ||
| print(discounted(100, "3")) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,10 @@ | |
|
|
||
| from telegram.ext import Updater, CommandHandler, MessageHandler, Filters | ||
|
|
||
| from datetime import date | ||
|
|
||
| import ephem | ||
|
|
||
| logging.basicConfig(format='%(name)s - %(levelname)s - %(message)s', | ||
| level=logging.INFO, | ||
| filename='bot.log') | ||
|
|
@@ -39,14 +43,31 @@ def greet_user(update, context): | |
| def talk_to_me(update, context): | ||
| user_text = update.message.text | ||
| print(user_text) | ||
| update.message.reply_text(text) | ||
| update.message.reply_text(user_text) | ||
|
|
||
| def get_planet_location(update, context): | ||
| text_message = update.message.text.split() | ||
| date_today = date.today().strftime("%Y/%m/%d") | ||
|
|
||
| if len(text_message) < 2: | ||
| return update.message.reply_text('Не указана планета.') | ||
|
|
||
| get_attribute = getattr(ephem, text_message[1], None) | ||
|
|
||
| if get_attribute is None: | ||
| return update.message.reply_text('Допущена ошибка вводе планеты.') | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Я бы рекомендовал третьим аргументом передвать None тут) семантически None - это ничего, как раз подходит сюда И обрати внимание на название переменных, из них не очень понятно что хранится внутри |
||
| planet = get_attribute(date_today) | ||
| constellation = ephem.constellation(planet) | ||
|
|
||
| update.message.reply_text(', '.join(constellation)) | ||
|
|
||
| def main(): | ||
| mybot = Updater("КЛЮЧ, КОТОРЫЙ НАМ ВЫДАЛ BotFather", request_kwargs=PROXY, use_context=True) | ||
|
|
||
| dp = mybot.dispatcher | ||
| dp.add_handler(CommandHandler("start", greet_user)) | ||
| dp.add_handler(CommandHandler("planet", get_planet_location)) | ||
| dp.add_handler(MessageHandler(Filters.text, talk_to_me)) | ||
|
|
||
| mybot.start_polling() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лайк!