forked from thisisshub/HacktoberFest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultiplication_table.py
More file actions
30 lines (24 loc) · 853 Bytes
/
multiplication_table.py
File metadata and controls
30 lines (24 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def multiplication_table():
user_input = int(input('Insert any number of multiplication: '))
row = [] # giving a row
# Make a columns and result the multiplication
for i in range(1, user_input+1):
row.append([])
for j in range(1, user_input+1):
row[i-1].append(i*j)
# return columns fit to the index
print(' *{:>3}|'.format(' '), end='')
for column in range(1, user_input+1):
print('{:^6}'.format(column), end='')
else:
print()
print('-' * (6 * (user_input+1)))
# print the result of the multiplication
for index, value, in enumerate(row):
print('{:^2}{:^3}|'.format(' ', index+1),end='')
for answer in value:
print(' {:^4} '.format(answer), end='')
else:
print('\n', end='')
print('-' * (6 * (user_input+1)))
multiplication_table()