From f8958ebe20522f5b0d32f33fd78870185912a67a Mon Sep 17 00:00:00 2001 From: himanshit0304 <70479061+himanshit0304@users.noreply.github.com> Date: Mon, 31 Oct 2022 04:25:11 +0530 Subject: [PATCH] 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 --- maths/print_multiplication_table.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 maths/print_multiplication_table.py diff --git a/maths/print_multiplication_table.py b/maths/print_multiplication_table.py new file mode 100644 index 000000000..dbe4a4be0 --- /dev/null +++ b/maths/print_multiplication_table.py @@ -0,0 +1,26 @@ +def multiplication_table(number: int, number_of_terms: int) -> str: + """ + Prints the multiplication table of a given number till the given number of terms + + >>> print(multiplication_table(3, 5)) + 3 * 1 = 3 + 3 * 2 = 6 + 3 * 3 = 9 + 3 * 4 = 12 + 3 * 5 = 15 + + >>> print(multiplication_table(-4, 6)) + -4 * 1 = -4 + -4 * 2 = -8 + -4 * 3 = -12 + -4 * 4 = -16 + -4 * 5 = -20 + -4 * 6 = -24 + """ + return "\n".join( + f"{number} * {i} = {number * i}" for i in range(1, number_of_terms + 1) + ) + + +if __name__ == "__main__": + print(multiplication_table(number=5, number_of_terms=10))