Turning in an item in a 2d array a specific colour based on user input

房东的猫 提交于 2019-12-24 08:57:03

问题


I have the following 2d array, displaying as a matrix. I wish to be able to specify the index number of a specific element in the 2d array and turn that number RED (or any colour). Can anyone point me in the right direction please?

Code so far:

>>> grid=[[28, 27, 26, 25,24,23,22], [21,20,19, 18, 17, 16, 15], [8, 9, 10, 11, 12, 13, 14], [7,   6,   5,   4,   3,   2,   1]]
>>> for i in grid:
    print(i)

Output:

[28, 27, 26, 25, 24, 23, 22]
[21, 20, 19, 18, 17, 16, 15]
[8, 9, 10, 11, 12, 13, 14]
[7, 6, 5, 4, 3, 2, 1]

For example:

print(grid[0][2])

Gives the output:

 26

I would like however, grid[0][2] to turn red, when the grid is displayed on the screen again.

To clarify, this is just expected to be output to the console. I am programming in IDLE --> New file. So output to the Python Shell ..I did google and found nothing, so realise this may not be an obvious fix or even a particularly useful thing to do. Still, it's a question .....

来源:https://stackoverflow.com/questions/41985139/turning-in-an-item-in-a-2d-array-a-specific-colour-based-on-user-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!