Answer the question
In order to leave comments, you need to log in
How to fix error when dividing in telegram bot?
Hi all. There is such code:
x = 50
y = x / 2
z = y
bot.send_message(message.from_user.id, 'Equals: ' +x)
bot.send_message(message.from_user.id, 'Andrew: ' +y)
bot .send_message(message.from_user.id, 'Artem: ' +z)
Error:
File "C:\Users\User\Desktop\monerrty.py", line 40, in get_text_messages
bot.send_message(message.from_user.id, 'Equals to: ' +x)
TypeError: can only concatenate str (not "int") to str
Answer the question
In order to leave comments, you need to log in
bot.send_message(message.from_user.id, 'Equals to: ' + str(x))
bot.send_message(message.from_user.id, 'Andrew: ' + str(y))
bot.send_message(message.from_user.id, 'Artem: ' + str(z))
OR
bot.send_message(message.from_user.id, f'Equals: {x}' )
bot.send_message(message.from_user.id, f'Andrey: {y}')
bot .send_message(message.from_user.id, f'Artem: {z}')
or
... there are other ways to format strings
UPD: the error occurs not because of division, but because of adding the string data str with an integer int
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question