S
S
svntxxnx2021-01-25 16:48:20
Python
svntxxnx, 2021-01-25 16:48:20

Why does the message local variable 'balanc' referenced before assignment come out?

I am writing a telegram bot and pytelegrambotapi

Here is a line of code:

elif call.data == 'four':
        if balanc >= 10:
            balanc = balanc - 10
            bot.answer_callback_query(call.id, "Ты купил кролика")
        elif balanc < 10:
            bot.answer_callback_query(call.id, "У вас недостаточно денег!")


When I press the "four" button on the callback, the bot Crashes and a message appears in the terminal:

"local variable 'balanc' referenced before assignment"

What could this be?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-01-25
@svntxxnx

Because the balanc variable is defined outside of this function

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question