Python lists and for loop

grid = [["-","-","-","-","-","-","-","-","-","-"], ["-","-","-","-","-","-","-","-","-","-"], ["-","-","-","-","-","-","-","-","-","-"],["-","-","-","-","-","-","-","-","-","-"],["-","-","-","-","-","-","-","-","-","-"],["-","-","-","-","-","-","-","-","-","-"],["-","-","-","-","-","-","-","-","-","-"],["-","-","-","-","-","-","-","-","-","-"],["-","-","-","-","-","-","-","-","-","-"],["-","-","-","-","-","-","-","-","-","-"]]
for i in grid:
    for j in range(10):
        print(i[j],end=" ")
    print()
print()

I created a 9*9 matrix but I want to number them so what should I do?

Ekran görüntüsü 2022-04-14 192245

I have just “-”

you wrote here what to put in there, so yeah you just get those in the output

what should I add for numbers

if you want numbers, you can write numbers

or you can write here what you want instead

1 Like
grid = [[" ",0,1,2,3,4,5,6,7,8,9],[0,"-","-","-","-","-","-","-","-","-","-"], [1,"-","-","-","-","-","-","-","-","-","-"], [2,"-","-","-","-","-","-","-","-","-","-"],[3,"-","-","-","-","-","-","-","-","-","-"],[4,"-","-","-","-","-","-","-","-","-","-"],[5,"-","-","-","-","-","-","-","-","-","-"],[6,"-","-","-","-","-","-","-","-","-","-"],[7,"-","-","-","-","-","-","-","-","-","-"],[8,"-","-","-","-","-","-","-","-","-","-"],[9,"-","-","-","-","-","-","-","-","-","-"]]
for i in grid:
    for j in range(11):
        print(i[j],end=" ")
    print()
print()

I wrote it by hand but it would take longer if it was long

what numbers do you want in there?

0,1,2,3,4,5,6,7,8,9 horizontally and vertically

Instead of manually writing grid, how could you individuate when you need a number and when you need a dash?

1 Like

yes ı wonder that …

Try to figure out - if you numbered the rows and columns, there is a relationship between what you want written and the indeces?

1 Like

I guess so -20character-

and what could that be?

It really helps if you make meaningful replies. We aren’t going to write the code for you, so your participation is an integral part of this process.

2 Likes

In your code, what value does j have?

i don’t know and i don’t understand i would write the code if i understood

these are “-” and numbers

In this code, j is not “-”.
Sorry, do you not know what you wrote there?

maybe, I’m beginner. I think j firstly wandering [" “,0,1,2,3,4,5,6,7,8,9] and i increase, j comes [1,”-","-","-","-","-","-","-","-","-","-"]

Have you written loops in Python before?

Do you know what this loop does?

for i in range(42):
    print(i)

it gives this 0,1,2,…,41