PYTHON练习题

题目1:假定有一个列表的列表,内层列表的每个值都是包含一个字符的字符串,像这样:
grid = [['.','.','.','.','.','.'],
        ['.','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','.','.'],
        ['.','0','0','.','.','.'],
        ['.','.','.','.','.','.'],]
你可以认为 grid[x][y]是一幅“图”在 x、y 坐标处的字符,该图由文本字符组成。原点(0, 0)在左上角,向右 x 坐标增加,向下 y 坐标增加。复制前面的网格值,编写代码用它打印出图像。
..00.00..


.0000000.


.0000000.


..00000..


...000...


....0....


答案:

grid = [['.','.','.','.','.','.'],
        ['.','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','.','.'],
        ['.','0','0','.','.','.'],
        ['.','.','.','.','.','.'],]

for y in range(6):
    for x in range(10):
        if x == 9:
            print('\n')
        else:
            print(grid[x][y], end='')

你可能感兴趣的:(PYTHON练习题)