I literally copy the solution, but it was shown wrong.why?


#1
for i in range(5):
  board.append(["0"] * 5)

this is my answer
error message said: It looks like your board contains characters other than “O”.

for i in range(5):
  board.append(['O'] * 5)

this is the solution and it works fine.
anyone has an idea of this situation?


#2

The difference that jumps out is the 0 (zero) as opposed to the O (oh).

We can run a simulation of each to compare the visual output…

>>> print ('\n'.join([' '.join(x) for x in [['O']*5]*5]))
O O O O O
O O O O O
O O O O O
O O O O O
O O O O O
>>> 

vs

>>> print ('\n'.join([' '.join(x) for x in [['0']*5]*5]))
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
>>> 

Not to be construed as a way to build the board.

>>> a = [['O'] * 5 for x in range(5)]
>>> print ('\n'.join([' '.join(x) for x in a]))
O O O O O
O O O O O
O O O O O
O O O O O
O O O O O
>>> a[1][1] = 'X'
>>> print ('\n'.join([' '.join(x) for x in a]))
O O O O O
O X O O O
O O O O O
O O O O O
O O O O O
>>> 

Just in case one is pursuaded to build upon the earlier example as a way to create the board. The above board, a, has addressable elements, not just addressable rows.

>>> def echo(n):
	print ('\n'.join([' '.join(x) for x in n]))

	
>>> echo(a)
O O O O O
O X O O O
O O O O O
O O O O O
O O O O O
>>> a[3][3] = 'X'
>>> echo(a)
O O O O O
O X O O O
O O O O O
O O O X O
O O O O O
>>> 

#3

Thank you sir,in the lesson i am not able to type the “0”, May i ask how can I achieve that?


#4

Shift letter o in quotes. 'O' or "O".


#5

Yes! That works perfectly,Thanks. I still have another problem with raw_input function in that lesson, after I press run button ,it takes a very long time to process and shows that my codes are wrong before I enter anything, do you know how to solve that problem? refreshing the webpage doesn’t work.


#6

Have you given inputs at the prompts?


#7

I did not , the error message occurred before I am allowed to enter anything.


#8

Let’s have a look at all your raw code, please.


#9
guess_row = int(raw_input("Guess Row: "))
guess_col = int(raw_input("Guess Col: "))

error message:Traceback (most recent call last):
File “python”, line 22, in
ValueError: invalid literal for int() with base 10: ‘SCT’


#10

Might be a necessary workaround… Set the two manually to something within range.


#11

I don’t understand it sorry, what is the meaning of set these two to something within range? you mean I should add something to it?


#12

set to means assign a value to, as in,

guess_row = 4
guess_col = 4

and comment out the two input lines. It will let you get through the lesson without getting the solution.


#13

Hi um… How do you start doing your own code?


#14

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.