How to Get a Multiplication Table in Python


In this example, we will learn the methods to obtain a multiplication table with a given number from 1 to A in Python.

Source Code

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

n = int(input("Please input the number: "))
for i in range(1, 11):
    print("{} * {:<2} = {:<3}".format(i, n, i * n))

Output:

Please input the number: 5
1 * 5  = 5
2 * 5  = 10
3 * 5  = 15
4 * 5  = 20
5 * 5  = 25
6 * 5  = 30
7 * 5  = 35
8 * 5  = 40
9 * 5  = 45
10 * 5  = 50

Please input the number: 15
1 * 15 = 15
2 * 15 = 30
3 * 15 = 45
4 * 15 = 60
5 * 15 = 75
6 * 15 = 90
7 * 15 = 105
8 * 15 = 120
9 * 15 = 135
10 * 15 = 150
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Advertisement