-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtelegram_errors_bot(lesson7).py
More file actions
40 lines (34 loc) · 1.37 KB
/
telegram_errors_bot(lesson7).py
File metadata and controls
40 lines (34 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from telegram.ext import Application, CommandHandler, MessageHandler
from telegram import Update
import logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
logger = logging.getLogger(__name__)
async def start(update: Update, context):
await update.message.reply_text("Привет! Тут будут только сообщения об ошибках")
while True:
a = input('Введите первое число: ')
if a in ('exit', 'учше'):
break
b = input('Введите второе число: ')
if b in ('exit', 'учше'):
break
error_text = ''
try:
print(f'Результат: {int(a) / int(b)}')
except ZeroDivisionError:
error_text = 'Ошибка: Деление на ноль!'
await update.message.reply_text(error_text)
except ValueError:
error_text = 'Ошибка ввода'
await update.message.reply_text(error_text)
except:
error_text = 'Ошибка'
await update.message.reply_text(error_text)
print(error_text)
def main():
token = "MY_TOKEN"
bot = Application.builder().token(token).build()
bot.add_handler(CommandHandler("start", start))
bot.run_polling()
if __name__ == '__main__':
main()