I understand there is another question on this already, however this is what I coded and wanted to know if this would raise any red flags?
Regarding the Character picture exercise located at the end the following page: https://automatetheboringstuff.com/chapter4/
Say you have a list of lists where each value in the inner lists is a one-character string, like this:
grid = [['.', '.', '.', '.', '.', '.'], ['.', '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', '.', '.'], ['.', 'O', 'O', '.', '.', '.'], ['.', '.', '.', '.', '.', '.']]
You can think of
grid[x][y]
as being the character at the x- and y-coordinates of a “picture” drawn with text characters. The(0, 0)
origin will be in the upper-left corner, the x-coordinates increase going right, and the y-coordinates increase going down.Copy the previous grid value, and write code that uses it to print the image.
..OO.OO.. .OOOOOOO. .OOOOOOO. ..OOOOO.. ...OOO... ....O....
It's different in that it doesn't hard-code the length of the list.
grid = [['.', '.', '.', '.', '.', '.'],
['.', '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', '.', '.'],
['.', 'O', 'O', '.', '.', '.'],
['.', '.', '.', '.', '.', '.']]
x = 0
y = 0
for y in range(len(grid[x])):
for x in range(len(grid)):
print(grid[x][y],end='')
print()
Thanks for the help and let me know if this is not appropriate to post!