From 1382ac27b97bb0ae322e0d849010e3c950828779 Mon Sep 17 00:00:00 2001 From: Himanshi Tiwari Date: Mon, 3 Oct 2022 16:13:35 +0530 Subject: [PATCH 1/4] Add print_multiplication_table.py --- 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 000000000000..0e99a56dcd83 --- /dev/null +++ b/maths/print_multiplication_table.py @@ -0,0 +1,26 @@ +def print_multiplication_table(number: int, number_of_terms: int): + """ + 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 + """ + for i in range(1,number_of_terms+1): + print(f"{number} * {i} = " + str(number*i)) + + +if __name__ == "__main__": + number = 5 + number_of_terms = 10 + print_multiplication_table(number,number_of_terms) \ No newline at end of file From 76606105d4686f10a5beea99c316c19ea184a487 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 3 Oct 2022 10:53:38 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/print_multiplication_table.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/maths/print_multiplication_table.py b/maths/print_multiplication_table.py index 0e99a56dcd83..d68120a5243e 100644 --- a/maths/print_multiplication_table.py +++ b/maths/print_multiplication_table.py @@ -16,11 +16,11 @@ def print_multiplication_table(number: int, number_of_terms: int): -4 * 5 = -20 -4 * 6 = -24 """ - for i in range(1,number_of_terms+1): - print(f"{number} * {i} = " + str(number*i)) - + for i in range(1, number_of_terms + 1): + print(f"{number} * {i} = " + str(number * i)) + if __name__ == "__main__": number = 5 number_of_terms = 10 - print_multiplication_table(number,number_of_terms) \ No newline at end of file + print_multiplication_table(number, number_of_terms) From e6602fc35453b927c3831acefec3bdfcd96c407a Mon Sep 17 00:00:00 2001 From: Himanshi Tiwari Date: Mon, 3 Oct 2022 16:28:24 +0530 Subject: [PATCH 3/4] Added return type description --- maths/print_multiplication_table.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/print_multiplication_table.py b/maths/print_multiplication_table.py index 0e99a56dcd83..ad8b2ec0471d 100644 --- a/maths/print_multiplication_table.py +++ b/maths/print_multiplication_table.py @@ -1,4 +1,4 @@ -def print_multiplication_table(number: int, number_of_terms: int): +def print_multiplication_table(number: int, number_of_terms: int) -> None: """ Prints the multiplication table of a given number till the given number of terms >>> print_multiplication_table(3,5) From ff1c1948f353819145a05c754052620c2a81d92c Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 30 Oct 2022 23:51:29 +0100 Subject: [PATCH 4/4] Update print_multiplication_table.py --- maths/print_multiplication_table.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/maths/print_multiplication_table.py b/maths/print_multiplication_table.py index c5649064fb8a..dbe4a4be0ee8 100644 --- a/maths/print_multiplication_table.py +++ b/maths/print_multiplication_table.py @@ -1,14 +1,15 @@ -def print_multiplication_table(number: int, number_of_terms: int) -> None: +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) + + >>> 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) + >>> print(multiplication_table(-4, 6)) -4 * 1 = -4 -4 * 2 = -8 -4 * 3 = -12 @@ -16,11 +17,10 @@ def print_multiplication_table(number: int, number_of_terms: int) -> None: -4 * 5 = -20 -4 * 6 = -24 """ - for i in range(1, number_of_terms + 1): - print(f"{number} * {i} = " + str(number * i)) + return "\n".join( + f"{number} * {i} = {number * i}" for i in range(1, number_of_terms + 1) + ) if __name__ == "__main__": - number = 5 - number_of_terms = 10 - print_multiplication_table(number, number_of_terms) + print(multiplication_table(number=5, number_of_terms=10))