Kamal Muradov
Kamal Muradov

Reputation: 49

My Python TeleBot Calculator doesn't work

This was the simplest code I've ever seen. My Python bot doesn't work. The thing that's not working is, it doesn't start to do anything when /start command is sent to bot. Logicaly, it must start the while loop - It doesnt. It even doesn't start with the function, FirstNum(). The idea was to use If - Else statement inside of loop.

Any suggestions? I am a beginner in python coding, so don't judge me strict)

@bot.message_handler(commands=['start'])
def Main(message):
  a = 0
  b = 0
  c = 0
  while a + b + c > 0:
    if a == 0:
      FirstNum(message)
      break
      if a > 0 & b == 0:
        SecondNum(message)
        break
        if a > 0 & b > 0 & c == 0:
          ThirdNum(message)
          break
          if a + b + c > 0:
            bot.send_message(message.chat.id,a + b + c.format(message.from_user, bot.get_me()))

def FirstNum(message):
  bot.send_message(message.chat.id,"Type your number > 0".format(message.from_user, bot.get_me()))
  a = message.text

def SecondNum(message):
  bot.send_message(message.chat.id,"Type your number > 0".format(message.from_user, bot.get_me()))
  b = message.text

def ThirdNum(message):
  bot.send_message(message.chat.id,"Type your number > 0".format(message.from_user, bot.get_me()))
  c = message.text

Upvotes: 2

Views: 589

Answers (1)

Alexander Morozov
Alexander Morozov

Reputation: 174

You have a logical error in the while loop condition. So obviously the while loop won't run, because condition 0 + 0 + 0 > 0 will be false.

Try a + b + c >= 0 condition in your while loop.

Upvotes: 1

Related Questions