Python Program to Print Multiplication Table

Python Program to Print Multiplication Table

Write a Python Program to Print Multiplication TablePython Programming examples interviewgigPrint Multiplication Table in Mathematics:

A multiplication table, also known as a times table, is a systematic arrangement of the products of two numbers. It shows the results of multiplying a specific number (the multiplicand) by consecutive integers (the multiplier). For example, the multiplication table for the number 5 would display the products 5×1, 5×2, 5×3, and so on.

Python Program to Print Multiplication Table:

Here’s a Python program that prints the multiplication table of a given number:

num = int(input("Enter a number: "))
print(f"Multiplication Table of {num}:")
for i in range(1, 11):
    product = num * i
    print(f"{num} x {i} = {product}")

Explanation:

  • The program starts by taking an integer input from the user using the input() function and converting it into an integer using the int() function. This input is stored in the variable num.
  • The program uses a for loop to iterate from 1 to 10 (for printing the multiplication table up to 10).
  • Inside the loop, the program calculates the product of num and i using the * operator and stores it in the variable product.
  • The program then uses the print() function to display the multiplication statement, formatted using an f-string.

Output:

Enter a number: 7
Multiplication Table of 7:
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
In this example, if the user enters 7, the program calculates and displays the multiplication table for the number 7, showing the products of 7 multiplied by each integer from 1 to 10.