M
M
MIKHAN_GO2020-07-28 07:09:47
Python
MIKHAN_GO, 2020-07-28 07:09:47

TypeError: 'int' object is not subscriptable, error with telebot?

Decided to write a simple bot with telebot, while doing this

k = 0 
 b = len(message.text()) 
 br = 0 
 lu = 0 
 run = True 
 while run: 
 if b[k] in slovar: 
 lu += slovar[b[k[first]]] 
 br += slovar[b[k[third]]] 
 k += 1 
 elif b[k] not in slovar: 
 k += 1 
 if k == b: 
 run = False 
 client.send_message(message.chat.id, "1 - " + lu + "%") 
 client.send_message(message.chat.id, "2 - " + br + "%") 
 k = 0 
 b = 0 
 br = 0 
 lu = 0 
 run = True


, throws an error with TypeError: 'int' object is not subscriptable, the line immediately after the if b[k] in slovar: loop is

something like this: slovar = {'а':{'first':'8', 'third': '5'}, ... } and so all letters, what to do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2020-07-28
@MIKHAN_GO

What do you k = 0think the expression should do k[first]? Moreover, the variable firstis not defined anywhere at all. I suspect it must be something like this slovar[b][k]['first'].

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question