Skip to content

Commit f5047c2

Browse files
Merge pull request #1490 from BBarbuz/master
Updated 'multiplication table' to make it really work
2 parents de994f8 + ddd100f commit f5047c2

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

multiplication_table.py

+22-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
from sys import argv # import argment variable
1+
"""
2+
The 'multiplication table' Implemented in Python 3
3+
4+
Syntax:
5+
python3 multiplication_table.py [rows columns]
6+
Separate filenames with spaces as usual.
7+
8+
Updated by Borys Baczewski (BB_arbuz on GitHub) - 06/03/2022
9+
"""
10+
11+
from sys import argv # import argument variable
212

313
(
414
script,
@@ -8,24 +18,17 @@
818

919

1020
def table(rows, columns):
11-
for i in range(
12-
1, int(rows) + 1
13-
): # it's safe to assume that the user would mean 12 rows when they provide 12 as an argument, b'coz 12 will produce 11 rows
14-
print(
15-
"\t",
16-
i,
17-
)
18-
19-
print("\n\n") # add 3 lines
20-
21-
for i in range(1, int(columns) + 1):
22-
print(i),
23-
for j in range(1, int(rows) + 1):
24-
print(
25-
"\t",
26-
i * j,
27-
)
28-
print("\n\n") # add 3 lines
21+
columns = int(columns)
22+
rows = int(rows)
23+
for r in range(1, rows+1):
24+
c = r
25+
print(r, end='\t')
26+
i = 0
27+
while columns-1 > i:
28+
print(c+r, end='\t')
29+
c = c+r
30+
i += 1
31+
print('\n')
2932

3033

3134
table(rows, columns)

0 commit comments

Comments
 (0)