0

Hello, I've been programming for 3 weeks and this is my first milestone project.

I was trying out a template for an interactive tic-tac-toe game. What I want to do is format the empty board with X's and O's from a list that is filled by user input.

emptyboard = """
    {1} | {2} | {3}
    ____|_____|____
    {4} | {5} | {6}
    ____|_____|____
    {7} | {8} | {9}
        |     |"""
print(emptyboard)
print(emptyboard.format(["#","X","O","O","O","O","X","X","X","X"]))

And I get an IndexError, yet I think that I have enough values in both my table and string formatting method. Output:

    {1} | {2} | {3}
    ____|_____|____
    {4} | {5} | {6}
    ____|_____|____
    {7} | {8} | {9}
        |     |
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-22-4c3674aa4a8b> in <module>
      7         |     |"""
      8 print(emptyboard)
----> 9 print(emptyboard.format(["#","X","O","O","O","O","X","X","X","X"]))

IndexError: tuple index out of range

Thanks in advance to everyone who tries to help! I will look up other ways of coding the game, but I'm just curious what my mistake is!

5
  • Without code, it would be difficult to answer this question. Commented Mar 19, 2020 at 10:53
  • @Psychemaster, thanks! I've added code. Commented Mar 19, 2020 at 11:00
  • @MontyMarti numbers should start at {0}, not {1} Commented Mar 19, 2020 at 11:07
  • @Nick, thanks! I looked it up and apparently a list is treated as a single item when used as an argument for the .format() method (and I need 10 arguments.) Commented Mar 19, 2020 at 11:31
  • @MontyMarti Oh, I didn't even notice that ^^", gj finding the solution though Commented Mar 19, 2020 at 11:36

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.