multiplication table
Table of Contents
In this article, we will discuss the python program to Generate multiplication table
In this program, we are going to learn how to generate a multiplication table using 3 ways in Python language.
This is done using for loop , while loop ,and function
In this program, we will display multiplication table of given number using for loop in Python language.
Program 1
num=int(input("Enter an integer"))
#Take input from the user
#iterate to times from i 1 - 10
for i in range(1,11):
print(num,'X', i,' = ',num*i) When the above code is executed , it produces the following result
Enter an integer 9 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
In this program, we will display multiplication table of given number using while loop in python language.
Program 2
num=int(input("Enter an integer"))
i=1
while i<=12:
print(num,'X', i,' = ',num*i)
i=i+1 When the above code is executed , it produces the following result
Enter an integer 13 13 * 1 = 13 13 * 2 = 26 13 * 3 = 39 13 * 4 = 52 13 * 5 = 65 13 * 6 = 78 13 * 7 = 91 13 * 8 = 104 13 * 9 = 127 13 * 10 = 130
In this program, we will display multiplication table of given number using function in Python language
Program 3
#Program to Generate multiplication table - using function
def multiTable(num): #function definition
for i in range(1,11):
print(num,'X', i,' = ',num*i)
#input a number
num=int(input("Enter an integer"))
#call the function
multiTable(num) When the above code is executed , it produces the following result
Enter an integer15 15 X 1 = 15 15 X 2 = 30 15 X 3 = 45 15 X 4 = 60 15 X 5 = 75 15 X 6 = 90 15 X 7 = 105 15 X 8 = 120 15 X 9 = 135 15 X 10 = 150
Suggested post
Similar post
Program to Display multiplication table in Java
Program to Display multiplication table in C
Multiply two numbers in Java using scanner| 5 different ways In this article, we will…
5 Different ways to Divide two numbers in Java using scanner In this article, we…
Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…
10 ways to subtract two numbers in Java In this article, we will discuss the…
Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…
How to Divide two numbers in Java| 5 different ways In this article, we will…
This website uses cookies.