0

Here is my current code:

row1 = ["","",""]
row2 = ["","",""]
row3 = ["","",""]

def gameTime ()
    print ( row1[0], row1[1], row1[2] )
    print ( row2[0], row2[1], row2[2] )
    print ( row3[0], row3[1], row3[2] )

while True:
    player1Row = input ( "Select a row: " )
    player1Column = input ( "Select a column: " )

    if player1Row == 1 and player1Column == 1:
        if row1[0] !="X" and row1[0] !="O":
            row1 [0] = "X"

    gameTime ()

I have attempted a few different strategies to replace the list index item [0] using .append() or even .remove() then .append() similarly to no avail. I feel like I am missing something because it works if I place value to the list items as 0,1,2 rather than "" but I wish to do it the way I have right now in order to complete the game. Any suggestions are appreciated. Thank you for your time!

Twissted
  • 71
  • 2
  • 10
  • 1
    `input` returns a string, but you are comparing its return to a int. – John Anderson Apr 07 '18 at 00:21
  • Edited. Ty Aran-Fey – Twissted Apr 07 '18 at 00:23
  • 1
    Possible duplicate of [How can I read inputs as integers?](https://stackoverflow.com/questions/20449427/how-can-i-read-inputs-as-integers) – Kevin J. Chase Apr 07 '18 at 00:33
  • @KevinJ.Chase Unfortunately, I did not know that was the issue going on. I had the program running previous using a different method but when I swapped my code around I ran into a wall. – Twissted Apr 07 '18 at 00:38
  • @Twissted: By claiming your question is a duplicate, I'm not saying you're stupid or wrong... for the bug or for the question. If this gets closed as a duplicate, it will remain on Stack Overflow as yet another real-world way someone got surprised by Python 3's `input` returning a string. Think of the "duplicate" message as expanding the funnel that leads to the more detailed answer, so that future visitors with this problem are slightly more likely to find the best solution. – Kevin J. Chase Apr 07 '18 at 00:47

1 Answers1

0

player1Row and player1Column are of type str.

however, list index is and should be of type int not str

need to convert the return of input to int

player1Row    = int(input ( "Select a row: " ))
player1Column = int(input ( "Select a column: " ))
Joseph D.
  • 11,804
  • 3
  • 34
  • 67