Python

Program to Multiplication table in given range using Python

Program to Multiplication table in given range using Python

In this article, we will discuss the concept of Program to Multiplication table in given range using Python

In this program, we are going to learn how to generate a multiplication table using several ways in Python language.

This is done using for loop , while loop and function in Python language

Program to Multiplication table in given range using Python for loop

In this program, we will display multiplication table of a number in given range using for loop in Python language

Program 1

#python program to print mutipication table
#of a number in given range
num=int(input("Enter the number: "))
ran=int(input("Enter the range: "))

print("Multiplication table of %d "%num)

for i in range(1,ran+1):
    print(num,"x",i,"=",num*i)

When the above code is executed, it produces the following result

Enter the number: 16
Enter the range: 12
Multiplication table of 16
16 x 1 = 16
16 x 2 = 32
16 x 3 = 48
16 x 4 = 64
16 x 5 = 80
16 x 6 = 96
16 x 7 = 112
16 x 8 = 128
16 x 9 = 144
16 x 10 = 160
16 x 11 = 176
16 x 12 = 192

 

  • integer variable num and ran are declared.
  • The program asks input from the user
  • Then the user enters the input values for num and ran.
  • The program will read the input using input stream and store to the variable num and ran respectively
  • Create a for loop of i from 1 to 12 and increase the value of i after every iteration by 1 using range() function
  • finally, the program displays the multiplication table using print() function.

 

Code to Multiplication table in given range using Python while loop

In this program, we will display multiplication table of a number in given range using while loop in Python language

Program 2

#python program to print mutipication table
#of a number in given range
num=int(input("Enter the number: "))
ran=int(input("Enter the range: "))

print("Multiplication table of %d "%num)
i=1;
while(i<=ran):
    print(num,"x",i,"=",num*i)
    i=i+1

When the above code is executed, it produces the following result

Enter the number: 11
Enter the range: 16
Multiplication table of 11
11 x 1 = 11
11 x 2 = 22
11 x 3 = 33
11 x 4 = 44
11 x 5 = 55
11 x 6 = 66
11 x 7 = 77
11 x 8 = 88
11 x 9 = 99
11 x 10 = 110
11 x 11 = 121
11 x 12 = 132
11 x 13 = 143
11 x 14 = 154
11 x 15 = 165
11 x 16 = 176

 

  • integer variable num and ran are declared.
  • The program asks input from the user
  • Then the user enters the input values for num and ran.
  • The program will read the input using input stream and store to the variable num and ran respectively
  • Create a while loop of i from 1 to 16 and increase the value of i after every iteration by 1 using range() function
  • finally, the code displays the multiplication table using print() function.

 

Code to Multiplication table in given range using Python function

In this program, we will display multiplication table of a number in given range using function in Python language

Program 3

#python program to print mutipication table
#of a number in given range
num=int(input("Enter the number: "))
ran=int(input("Enter the range: "))

print("Multiplication table of %d "%num)
def mul_Table(num):#function definition
  for i in range(1,ran+1):
    print(num,"x",i,"=",num*i)

mul_Table(num)#function call

When the above code is executed, it produces the following result

Enter the number: 9
Enter the range: 16
Multiplication table of 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
9 x 11 = 99
9 x 12 = 108
9 x 13 = 117
9 x 14 = 126
9 x 15 = 135
9 x 16 = 144

 

Suggested post

For loop in Python

While loop in Python

Function in python

Operator in Python

Data type in Python

 

Similar post

Code to Display multiplication table in Java

Code to Display multiplication table in C

code to Display multiplication table in C++

Code to Display multiplication table in Python

Karmehavannan

Recent Posts

Multiply two numbers in Java using scanner| 5 different ways

Multiply two numbers in Java using scanner| 5 different ways In this article, we will…

3 months ago

5 different ways to Divide two numbers in Java using scanner

5 Different ways to Divide two numbers in Java using scanner In this article, we…

3 months ago

Learn 8 Ways to Subtract Two Numbers Using Methods in Java

Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…

4 months ago

10 ways to subtract two numbers in Java

10 ways to subtract two numbers in Java In this article, we will discuss the…

4 months ago

Java Code Examples – Multiply Two Numbers in 5 Easy Ways

Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…

4 months ago

How to Divide two numbers in Java| 5 different ways

How to Divide two numbers in Java| 5 different ways In this article, we will…

4 months ago

This website uses cookies.