[Tutor] (no subject)

Jacob Bender benderjacob44 at gmail.com
Wed Jan 19 22:09:23 CET 2011


Dear tutors,

     I'm writing a program that can play Othello. Everything has been 
going fine, but there is a frequently occurring problem with printing 
the board with the squares filled in. Here's the code for the board:

class board(object):
     def create_board(self): #Create a virtual board, that will be played on
         self.board = []
         for squares in range(64):
             self.board.append(" ")


         self.board_table =\
             """

    A  B  C  D  E  F  G  H
1 |%s|%s|%s|%s|%s|%s|%s|%s|
2 |%s|%s|%s|%s|%s|%s|%s|%s|
3 |%s|%s|%s|%s|%s|%s|%s|%s|
4 |%s|%s|%s|%s|%s|%s|%s|%s|
5 |%s|%s|%s|%s|%s|%s|%s|%s|
6 |%s|%s|%s|%s|%s|%s|%s|%s|
7 |%s|%s|%s|%s|%s|%s|%s|%s|
8 |%s|%s|%s|%s|%s|%s|%s|%s| """

    def display_board(self):
         print self.board_table % self.board

v = board()
v.create_board()
v.display board()

I get this error:

Traceback (most recent call last):
   File "C:\Documents and Settings\Owner\My 
Documents\Dropbox\Shared_With_Chris\Jake's 
Programs\AI\Othello_Unfinished.py", line 76, in <module>
     v.display_board()
   File "C:\Documents and Settings\Owner\My 
Documents\Dropbox\Shared_With_Chris\Jake's 
Programs\AI\Othello_Unfinished.py", line 72, in display_board
     print self.board_table % self.board
TypeError: not enough arguments for format string

I tried doing:

    def display_board(self):
         print self.board_table % self.board[:]

But that didn't help either, and I still got the same TypeError. If you 
could please figure out what's wrong, it would be greatly appreciated. 
Thanks!


More information about the Tutor mailing list