F
F
fuckingfamouscoder2020-04-21 13:53:03
Python
fuckingfamouscoder, 2020-04-21 13:53:03

How to fix my BlackJack code in Python?

the code

@bot.message_handler(content_types=['text']) # Ответ бота на текстовые команды
def send_text(message): # Функция отправки текста в ТГ
    if message.text == "Играть":
        def ochko(message):
            koloda = [6,7,8,9,10,2,3,4,11] * 4
            import random
            random.shuffle(koloda)
            bul = True
            count = 0
            dealercount = 0
            newcard = koloda.pop()
            startuser = koloda.pop() + koloda.pop()
            startdealer = koloda.pop()
            count += startuser
            dealercount += startdealer
            
            print(startdealer)
            print(startuser)   
            def ochkoplay(message, count, dealercount):
                while bul:
                    if message.text == "Добрать":
                        newcard = koloda.pop()
                        count+=newcard
                        dealercount += koloda.pop()
                        print(count)
                        if count > 21:
                            bot.send_message(message.chat.id, "Вы вытянули карту с номиналом " + str(newcard) + "\nВаш счёт - %a\nПеребор - вы проиграли" %(count), parse_mode='HTML', reply_markup=kb21)
                            break
                        elif count == 21:
                            bot.send_message(message.chat.id, "Эйс, 21!\nВы выиграли!\nСчёт дилера - %a" %(dealercount), parse_mode='HTML', reply_markup=kb21)
                            break
                        else:
                            bot.send_message(message.chat.id, "Вы вытянули карту с номиналом " + str(newcard) + "\nВаш счёт - %a" %(count), parse_mode='HTML', reply_markup=kb21)
                    if message.text == "Вскрыться":
                        print(" ")
                    
            sent = bot.send_message(message.chat.id, "Ваш cчёт: %a\nСчёт дилера: %a" %(count, dealercount), parse_mode='HTML', reply_markup=kb21)
            bot.register_next_step_handler(sent, ochkoplay) 
        ochko(message, count, dealercount)


When I run it, it says that def ochko will not find the variables that it should take, but they are listed exactly above. If you insert ochko(message) without "count" and "dealer", then the game function stops working, when you click on the "Get" button, it will not find the count variable. How to fix the code so that a normal game comes out? The logic is clear, the "Open" button has not yet been added, there are also some problems with the cycle :(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Krostelev, 2020-04-21
@fuckingfamouscoder

bot.register_next_step_handler(sent, ochkoplay )
ochkoplay - a function that expects input parameters

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question