1

enter image description here

def is_table(tab):
   if len(tab) != 3:
      return False
   valid = (-1, 0, 1)
   for a in range(0, 3):
      if len(tab[a]) != 3:
         return False
      for b in range(0, 3):
         if tab[a][b] not in valid:
            return False
   return True

When I try to run is_table(((0,0,0),(0,0,0),(0,0,0))) on console, I get this error:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
NameError: name 'is_table' is not defined

Can anyone explain why? My function is clearly defined, but it still doesn't run on console.

Red
  • 26,798
  • 7
  • 36
  • 58
sousa16
  • 23
  • 6

3 Answers3

1

The python console dont know about your files functions. First, edit your file name, removing any space, e.g., jogo_do_galo.py (or another name, like jogo_do_mengao).

Open the python console, and try:

>>> from jogo_do_galo import *
>>> tab = ((True, 0, 0), (0, 0, 0), (0, 0, 0))
>>> eh_tabuleiro(tab)

This will work.

André Ginklings
  • 353
  • 1
  • 11
0

Did you define the function inside the console, or in a separate file?

If you defined the function in a separate file, you'll need to run the file before the function will be recognized by the console.

Red
  • 26,798
  • 7
  • 36
  • 58
0

Found an answer. Right-clicked on file name, settings, run on console.

sousa16
  • 23
  • 6