list - How to get user input of a grid of characters in Python -
I am very new to Python, so I do not know much about its syntax.
So I want to give the number of rows and columns of a grid as an input, and then input a grid of rare characters with the number of rows and columns. For example:
If I have an input:
3 4 XOXOXXXXOOOO
I want to print an array like this: 'X', 'X', 'X', 'X', 'X', ['x', 'o', 'x', 'o'], ['x' o ',' o I have so far:
line, column = [int grid [i], 'o', 'o']]
Append ([]) grid [i] = raw_input (). Split () for (x) raw_input in x () Split ()] Grid = []
I'm getting the error: The list index is out of range
I'm not sure what I'm doing wrong Also assistance will be appreciated.
The problem is a blank list. You can not reference grid [i]
where i
is out of range.
attach
to grid
, in this way:
for the category I (n): # 0 contained grid .append (raw_input (). Split ())
grid [i]
Comments
Post a Comment