Skip to content

Commit f8958eb

Browse files
himanshit0304pre-commit-ci[bot]cclauss
authored
Add print_multiplication_table.py (#6607)
* Add print_multiplication_table.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Added return type description * Update print_multiplication_table.py Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christian Clauss <[email protected]>
1 parent c0168cd commit f8958eb

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Diff for: maths/print_multiplication_table.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
def multiplication_table(number: int, number_of_terms: int) -> str:
2+
"""
3+
Prints the multiplication table of a given number till the given number of terms
4+
5+
>>> print(multiplication_table(3, 5))
6+
3 * 1 = 3
7+
3 * 2 = 6
8+
3 * 3 = 9
9+
3 * 4 = 12
10+
3 * 5 = 15
11+
12+
>>> print(multiplication_table(-4, 6))
13+
-4 * 1 = -4
14+
-4 * 2 = -8
15+
-4 * 3 = -12
16+
-4 * 4 = -16
17+
-4 * 5 = -20
18+
-4 * 6 = -24
19+
"""
20+
return "\n".join(
21+
f"{number} * {i} = {number * i}" for i in range(1, number_of_terms + 1)
22+
)
23+
24+
25+
if __name__ == "__main__":
26+
print(multiplication_table(number=5, number_of_terms=10))

0 commit comments

Comments
 (0)