Multiplication table function

EasyFunction Programs · 3 of 39

Write a Python function that prints the multiplication table of a number.

Advertisement
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

  1. Loop from 1 to 10 and print each line.

Solution

Python
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
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More function programs

← All 39 Function Programs