Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
Python program to Multiply two integers|in 5ways

Python program to Multiply two integers|in 5ways

Posted on September 3, 2020September 6, 2020

Table of Contents

  • Python program to Multiply two integers|in 5ways
    • Program to Multiply two integers
      • Program to Multiply two integers – standard method
      • Program to Multiply two integers – using user input
      • Program to Multiply two integers – using function
      • Program to Multiply two integers – using recursion
      • Program to Multiply two integers – using without * operator

Python program to Multiply two integers|in 5ways

In this tutorial, we will discuss the Python program to Multiply two integers|in 5ways

In this post, we are going to learn how to find multiplication of two numbers via different 5 ways in Python language

Program to Multiply two integers

Program to Multiply two integers – standard method

Program 1

#Python program to mutipy two numbers
num1=15
num2=16
mul=num1 * num2;
print("Multiplication of two numbers: ",mul)

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

Multiplication of two numbers:  240
  • Integer variable num1 and num2 both are declared and initialized
  • the num1 and num2 both are multiplied together and the value is assigned to the integer variable mul
  • finally the program is displayed the output using print() function

Program to Multiply two integers – using user input

Program 2

#Python program to mutipy two numbers
num1=int(input("Enter first number: "))
num2=int(input("Enter second number: "))
#input numbers from the user

mul=num1 * num2;#caculate multipication

print("Multipication of two numbers: ",mul)
#display output

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

Enter first number: 12
Enter second number: 24
Multiplication of two numbers:  288

 

Approach

  • Integer variable num1 and num2 both are declared,
  • The program takes input from the user
  • Then the user enters the input value for num1, num2
  • the program will read the input and store the variables in num1, num2.
  • the num1 and num2 both are multiplied together and the value is assigned to the integer variable mul
  • finally the program is displayed the output using print() function

 

Program to Multiply two integers – using function

Program 3

#Python program to multiply two numbers using function

def multiply(num1,num2):#function definition
    product=num1 * num2
    return product

num1=int(input("Enter first number "))
num2=int(input("Enter second number "))
#input numbers from the user

result=multiply(num1,num2)#caling the function

print("Multipication of two numbers: ",result)
#display output

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

Enter first number 12
Enter second number 21
Multiplication of two numbers:  252

 

Approach

  • Integer variable num1 and num2 both are declared,
  • The program takes input from the user
  • Then the user enters the input value for num1, num2
  • the program will read the input  store the variables in num1, num2.
  • define the function for find product of two numbers
  • When we call the function, the num1 and num2 both are multiplied together
  • Then the value is assigned to the integer variable result
  • finally the program is displayed the output using print() function

 

Program to Multiply two integers – using recursion

Program 4

def product(x,y):
    if(x<y):
        return product(y,x)
    elif(y!=0):
        return (x+product(x,y-1))
    else:
        return 0

x=int(input("Enter first number: "))
y=int(input("Enter second number: "))

print("Product is ", product(x,y))

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

Enter first number: 100
Enter second number: 50
('Product is ', 5000)

Approach

  • Integer variable x and y both are declared,
  • The program takes input from the user
  • Then the user enters the input value for x and y
  • the program will read the input  store the variables in  x , y.
  • define the recursive function for multiply two numbers
  • When we call the function, the x and y both are multiplied recursively
  • finally the program is displayed the output using print() function

 

Program to Multiply two integers – using without * operator

Program 5

num1=int(input("Enter first number: "))
num2=int(input("Enter second number: "))
product=0
for i in range(1,num2+1):
    product=product+num1
print("Product is ", product)

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

Enter first number: 50
Enter second number: 60
Product is 3000

 

Suggested post

Function in Python language

Operator in Python language

Data type in Python

 

 

Similar post

Find product of two numbers in Java language|5ways

Find product of two numbers in C language|6ways

Find product of two numbers in C++ language|6ways

 

 

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes