Ask coding questions

← Back to all posts
What goes wrong?
BearCoder01

I got an error on line 104. When you buy nothing (buy the table) you get an error TypeError: 'int' object is not subscriptable. What can I do?. Please help.

Voters
BearCoder01
Comments
hotnewtop
Coder100

Here is why

if you haven't realized, you overrode the global items variable with your own variable that was part of the original items array, so rename that items variable.

BearCoder01

@Coder100 what do you mean?

OldWizard209

Yeah this happens when u try to access an integer as if it were a subscribable object, like a list. Take a look here to solve the issue.
I would've helped you but your code is long so I didnt bother. Sorry

BearCoder01

@OldWizard209 This only happens only is you bought (a table) in the first part of the code (`printBuyItems()) there is an error, but if you doesn't buy something (hit the [ETNTER] then there isn't an error.

VulcanWM

Try removing the brackets from i?

BearCoder01

@VulcanWM Still got the problem.

VulcanWM
BearCoder01

@VulcanWM I get this error only if I have bought something before.

OldWizard209