UnboundLocalError: local variable 'money' referenced before assignment
в боте есть лотерея, участи в которой стоит 5 монет. 1% шанс на выигрыш в 100 монет, 10% шанс на выигрыш в 20 монет, иначе ничего. но когда я запускаю бот, мне пишет :
UnboundLocalError: local variable 'money' referenced before assignment.
код:
import telebot
import random
money = 100
bot = telebot.TeleBot('token')
keyboard1 = telebot.types.ReplyKeyboardMarkup(True, True)
keyboard1.row('/mymoney', '/info')
@bot.message_handler(commands=['lotery'])
def lotery(message):
money = money - 5
if random.randint(1, 100) == 2 or random.randint(1, 100) == 3 or random.randint(1, 100) == 4 or random.randint(1, 100) == 5 or random.randint(1, 100) == 6:
bot.send_message(message.chat.id, 'Забирай свои 20 дуркоинов.', reply_markup=keyboard1)
money = money + 20
elif random.randint(1, 100) == 7 or random.randint(1, 100) == 8 or random.randint(1, 100) == 9 or random.randint(1, 100) == 10 or random.randint(1, 100) == 11:
bot.send_message(message.chat.id, 'Забирай свои 20 дуркоинов.', reply_markup=keyboard1)
money = money + 20
elif random.randint(1, 100) == 1:
bot.send_message(message.chat.id, 'ты выиграл. Забирай 100 дуркоинов.', reply_markup=keyboard1)
money = money + 100
else:
bot.send_message(message.chat.id, 'Ты проиграл.', reply_markup=keyboard1)
@bot.message_handler(commands=['start'])
def start_message(message):
bot.send_message(message.chat.id, 'Начинаю работу.', reply_markup=keyboard1)
@bot.message_handler(commands=['mymoney'])
def my_money(message):
bot.send_message(message.chat.id, 'У тебя %s дуркоинов' % money, reply_markup=keyboard1)
@bot.message_handler(commands=['info'])
def info(message):
bot.send_message(message.chat.id, 'Банк Республики Дурка. /mymoney - мой счёт. /lotery - лотерея. Цена билета - 5 дуркоинов.', reply_markup=keyboard1)
bot.polling()