Printing a full Matrix with coordinates python 3 | بلاگ

Printing a full Matrix with coordinates python 3

تعرفه تبلیغات در سایت

آخرین مطالب

امکانات وب

Vote count: 0

import random
grid = []
n=m=5
NG = [random.randint(0,n-1) for x in range(n)]
for i in range(5):
        grid.append((i,NG[i]))
Matrix = {(x,y):"-" for x in range(n) for y in range(m)}
point1 = (1, 2)
for i in range(len(grid)):
    Matrix[grid[i]] = "Q"
for i in range(0, len(grid)):
      for j in range(i, len(grid)):
            print(Matrix[(i,j)], end=' ')
      print()

output Q - - - - - - Q -


- Q

I need everything to be filled in therefore if it is a 5x5 matrix all 25 spaces are occupied. If the coordinate is in Matrix then it gets a "Q" else it gets a "-"

asked 1 min ago
Emily Stapler

...
نویسنده : استخدام کار بازدید : 7 تاريخ : سه شنبه 24 بهمن 1396 ساعت: 10:43