nick34992
6/18/2017 - 8:20 PM

Python: CLI Multiplication Table

Python: CLI Multiplication Table

'''Prints multiplication table with both column and row headings.

While each column value is less than 13, print X * Y,
print rows of multiplication tables.

prints blank space, upper-left corner
`end = ' '` replaces `\n` with a space'''

X = 1  # row
Y = 1  # column

print ('{:>3}'.format(' '), end=' ')

# prints column headings
for X in range(1, 13):
    print('\x1b[0;31;40m{:>3}\x1b[0m'.format(X), end=' ')
print()

# prints row headings
for X in range(1, 13):
    print('{:>3}'.format(X), end=' ')

    # prints multiplication table
    while Y < 13:
        # print multiples
        print('{:>3}'.format(X * Y), end=' ')
        Y += 1  # Y counter
    print()
    Y = 1  # resets Y counter after row prints