'int' Object is not subscriptable, I have tested several times but whenever text I receive this message

Asked

Viewed 573 times

-2

def movinteiros(a):
    b=[]
    for i in a:
        if i=="c":
            b.append([-1,0])
        elif i=="b":
            b.append([1,0])
        elif i=="d":
            b.append([0,1])
        else:
            b.append([0,1])
    return b



opcao=int(input("Opcao de jogo:"))
n=int(input("Tamanho do tabuleiro:"))
matriz=[int(x) for x in input("Tabuleiro inicial:").split()]

If the entrees are:

1

2



1 2
3 0

ce

the function trocapos should return:

  • I advise you to carefully read the community guidelines of how to ask a good question.

  • This entry seems to be insufficient to reproduce the problem. When placing the cited entries the program still asks for "Movements".

  • For that entrance, matriz is getting [1, 2, [3, 0]]. Should she be like this? Or should she be [[1, 2], [3, 0]]?

  • should be [[1, 2], [3, 0]]

  • If the entries are: 1 2 ce 1 2 3 0

  • Then you must have realized that the shape you’ve generated matriz is not correct.

  • Please don’t make more work for other people by vandalizing your posts. By posting on Stack Overflow, you’ve granted a non-revocable right, under the CC BY-SA 3.0 Icense for SO to Distribute that content. By SO policy, any vandalism will be reverted. If you want to know more about deleting a post, Pread more How does deleting work?

Show 2 more comments

1 answer

0

This error appears because you are trying to use an object that is an integer as if it were a list or a dictionary, using brackets after the same - let’s assume that the object is in the variable x - you when programming assumed that x should have a list or dictionary and wrote x[0] or x["nome"], but x actually contains a whole.

Then in this case this error message appears, accompanied by the error line. Since you didn’t put the error line, there is also no reason for someone to run your program from the head and search on which line it is - the information is on your screen.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.