M
M
maximaliev952021-08-04 19:20:00
Python
maximaliev95, 2021-08-04 19:20:00

How to make the telegram bot answer with an already calculated number?

How to make the bot able to calculate pro on its own, without the participation of the owner? For example, the user wants to know what the amount will be if 600 is divided by 0.6 The example below shows what I want to do, but I can't figure it out.

The user writes: 600 The
bot replies with the already calculated amount: 1000

How to teach the bot to calculate
? Tell me, please, who knows.
telegrambot, python

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vindicar, 2021-08-04
@Vindicar

1. Set the "incoming message" handler.
2. Run the message text through float(), and for reliability, you can try using locale.atof() - it understands regional formatting. For example, in the USA the amount is "5,000.00" and in our country it is "5,000.00", and both there and there they can simply write "5000". It won't be easy to pick out all the options, but atof() will do for a start.
3. Calculate the interest.
4. Reply to the message with the calculated percentage.
That's all. If you want the code, please provide what you wrote yourself (and decorate with the </> button).

R
RusiDev, 2021-08-05
@RusiDev

The user writes: 600 The
bot responds with the already calculated amount: 1000
We receive data from the user: 200
Create a variable, let's say
x = int(data from the user) (in order to convert the string to a numeric value) Bot's
response: {x} * 0.6
If Post the code, I can explain more

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question