Python Practice › Function Programs › Program 3
Multiplication table function
Write a Python function that prints the multiplication table of a number.
Input
9
Output
9 x 1 = 9 9 x 2 = 18 9 x 3 = 27 9 x 4 = 36 9 x 5 = 45 9 x 6 = 54 9 x 7 = 63 9 x 8 = 72 9 x 9 = 81 9 x 10 = 90
Approach
- Loop from 1 to 10 and print each line.
Solution
def table(n, upto=10): for i in range(1, upto + 1): print(f"{n} x {i:2} = {n * i}") table(9)Output
9 x 1 = 9 9 x 2 = 18 9 x 3 = 27 9 x 4 = 36 9 x 5 = 45 9 x 6 = 54 9 x 7 = 63 9 x 8 = 72 9 x 9 = 81 9 x 10 = 90
Learn the concept
New to this topic? Read the lesson, then come back.