Hi I have small problem I dont know how to add oder like from 1 to number 8 on the right and on the left of this program. Here is the list but How to add numbers on the left and on the righ. I did this with letters up and down
Here is my code
sachy = [[0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 2, 0, 2, 0, 2], [2, 0, 2, 0, 2, 0, 2, 0], [0, 2, 0, 2, 0, 2, 0, 2]]
poradi = ["a", "b", "c", "d", "e", "f", "g", "h"]
poradi_2 = [1, 2, 3, 4, 5, 6, 7, 8]
for prvek in poradi:
print(prvek, end=" ")
print()
print()
for seznam in sachy:
for prvek in seznam:
print(prvek, end=" ")
print(end="\n", )
print()
for prvek in poradi:
print(prvek, end=" ")
I try to write another list of order from 1 to 8 into the seznam but will always multiple by 8 becaouse of sachy that are 8x8.
You need to pair the row indices with the row itself, also use " ".join()
for shorted code
print(" ", " ".join(poradi), "\n")
for idx, seznam in zip(poradi_2, sachy):
print(idx, " ".join(map(str, seznam)), idx)
print("\n ", " ".join(poradi), "\n\n")
a b c d e f g h
1 0 1 0 1 0 1 0 1 1
2 1 0 1 0 1 0 1 0 2
3 0 1 0 1 0 1 0 1 3
4 0 0 0 0 0 0 0 0 4
5 0 0 0 0 0 0 0 0 5
6 0 2 0 2 0 2 0 2 6
7 2 0 2 0 2 0 2 0 7
8 0 2 0 2 0 2 0 2 8
a b c d e f g h
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.