Python Practice › Loop Programs › Program 40

Multiplication table

EasyLoop Programs · 40 of 90

Write a Python program to print the multiplication table of a number.

Advertisement
Input
7
Output
7 x  1 =   7
7 x  2 =  14
7 x  3 =  21
7 x  4 =  28
7 x  5 =  35
7 x  6 =  42
7 x  7 =  49
7 x  8 =  56
7 x  9 =  63
7 x 10 =  70

Approach

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

Solution

Python
n = 7for i in range(1, 11):    print(f"{n} x {i:2} = {n * i:3}")
Output
7 x  1 =   7
7 x  2 =  14
7 x  3 =  21
7 x  4 =  28
7 x  5 =  35
7 x  6 =  42
7 x  7 =  49
7 x  8 =  56
7 x  9 =  63
7 x 10 =  70

Line by line

Line 3

The widths :2 and :3 right-align the columns.

Learn the concept

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

More loop programs

← All 90 Loop Programs

Leave a Comment