0

Hey so I am trying to map out the first Row and first column with numbers but finding some difficulty here what ever got so far

output = " "
column_count = 0
row_count = 1
for row in range(10):
output = " "
 for column in range(20):
    if (row == 0):
        while column_count <= 20:
            print(column_count, end = " ")
            column_count += 1
    elif (column == 0):
        while row_count <= 10:
            print(row_count)
            row_count += 1
    else:
        output += "x"

print(output)               
 

this my output

so something like this but mapped out perfectly

Fatz
  • 5
  • 1

1 Answers1

0

From my understanding of your question, you're essentially looking for a grid like you would find for multiplication tables except with 'X' instead of products.

Below is an adaptation of this answer to the question How to print a 10*10 times table as a grid?.

# Set Number of Rows and Columns
cols = 21
rows = 11

# Determine width of each column based on largest column
space_fmt = f'{{:>{len(str(cols)) + 1}}}'

# Print Header Row
print(''.join(space_fmt.format(i) for i in range(0, cols)))
# Print Remaining Rows
for y in range(1, rows):
    # Print First Number
    print(space_fmt.format(y), end='')
    # Print Xes
    print(''.join([space_fmt.format('X') for _ in range(1, cols)]))

An answer with just for loops, no join on list comprehensions

# Set Number of Rows and Columns
cols = 21
rows = 11

# Determine width of each column based on largest column
space_fmt = f'{{:>{len(str(cols)) + 1}}}'

# Print Header Row
for i in range(0, cols):
    print(space_fmt.format(i), end='')
print()  # New Line
# Print Remaining Rows
for y in range(1, rows):
    # Print First Number
    print(space_fmt.format(y), end='')
    # Print Xes
    for col in range(1, cols):
        print(space_fmt.format('X'), end='')
    print()  # New Line
Henry Ecker
  • 34,399
  • 18
  • 41
  • 57