OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to resolve the error "typeError 'int' object is not subscriptable"

  • Thread starter Thread starter 808Blues
  • Start date Start date
8

808Blues

Guest
I'm making a Connect Four game for a class and I'm running into an error with my play function.

Code:
def play(grid,column,checker):
    
    counter = 0
    for x in grid[0]:
        counter += 1
    print(counter)
    if counter > column-1 :
        for row in reversed(grid):
            if row[column-1] == "empty":
                row[column-1] = checker
                print(True)
                return True,grid,checker
    else:
        print(False)
        return False  , grid , checker

The problem occurs at line 9 (if row[column-1] == "empty") and I keep getting

typeError 'int' object is not subscriptable

grid is a global variable returned from a different function.
<p>I'm making a Connect Four game for a class and I'm running into an error with my play function.</p>
<pre><code>def play(grid,column,checker):

counter = 0
for x in grid[0]:
counter += 1
print(counter)
if counter > column-1 :
for row in reversed(grid):
if row[column-1] == "empty":
row[column-1] = checker
print(True)
return True,grid,checker
else:
print(False)
return False , grid , checker
</code></pre>
<p>The problem occurs at line 9 (<code>if row[column-1] == "empty"</code>) and I keep getting</p>
<blockquote>
<p>typeError 'int' object is not subscriptable</p>
</blockquote>
<p><code>grid</code> is a global variable returned from a different function.</p>
 

Latest posts

D
Replies
0
Views
1
Danish Karmally
D
Top