Currently strugging with nicely printing a array of "O"'s, where the columns and rows should be numbered.
So I have a array which is just a nxn-matrix full of the string "O". Now I tried using the following method:
def __repr__(self) :
Matrix = self.Spielstand #this is just the mentioned array of length n:
Ausgabe = " "
for j in range(len(Matrix[0])):
Ausgabe += str(j + 1) + " "
Ausgabe += "\n"
for i in range(len(Matrix)):
Ausgabe += str(i + 1) + " "
for j in range(len(Matrix[i])):
Ausgabe += str(Matrix[i][j])
Ausgabe += " "
Ausgabe += "\n"
return Ausgabe
Which works perfectly fine printing something like:
1 2 3 4 5 6 7 8
1 O O O O O O O O
2 O O O O O O O O
3 O O O O O O O O
4 O O O O O O O O
5 O O O O O O O O
6 O O O O O O O O
7 O O O O O O O O
8 O O O O O O O O
However when my n gets bigger than 9, things get kind of weird:
1 2 3 4 5 6 7 8 9 10
1 O O O O O O O O O O
2 O O O O O O O O O O
3 O O O O O O O O O O
4 O O O O O O O O O O
5 O O O O O O O O O O
6 O O O O O O O O O O
7 O O O O O O O O O O
8 O O O O O O O O O O
9 O O O O O O O O O O
10 O O O O O O O O O O
Is there a simple and nice way (preferably without using external libraries) to print the array nicely even if my n is double or even triple digit? I think using f-Strings and something going from center should work, but I have no clue how to implement it. Thanks for your help!