MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / multiplication_table

Function multiplication_table

maths/print_multiplication_table.py:1–22  ·  view source on GitHub ↗

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

(number: int, number_of_terms: int)

Source from the content-addressed store, hash-verified

1def 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
25if __name__ == "__main__":

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected