[Tutor] Tic-Tac-Toe

Alan Gauld alan.gauld at btinternet.com
Sun Feb 20 01:34:54 CET 2011


"Ben Ganzfried" <ben.ganzfried at gmail.com> wrote

>    if (cell % 3 == 0) and (self.__mycells[cell] == 
> self.__mycells[cell +
> 1]) and (self.__mycells[cell + 1]== self.__mycells[cell + 2]):
> TypeError: unsupported operand type(s) for %: 'instance' and 'int'

The error is in the first expression and the message tells you
what is wrong. You are trying to use the % operator on an
instance.

Looking at your code, sure enough...

>    def gameWon(self):
>        for cell in self.__mycells:
>            if (cell % 3 == 0) and (self.__mycells[cell] ==

cell is one of __mycells which are objects.

You need to rethink this test.

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list