Python Program To Multiply Two Numbers Using Function

Python program to multiply two numbers using function is provided on this page.

Python Program To Multiply Two Numbers Using Function

Program 1

In this program we simply set two numbers and multiply using * operator.


#Python program to multiply two numbers using function
#function for find product
def multiply(a,b):
    multiplication = a * b;
	return multiplication

# set two numbers
first_number = 30  
second_number = 110
print("The product is ", multiply(first_number, second_number))

Program 2

Here we do the same thing except the number are accepted from user. Observe only integers will be accepted even if user enters floating point.


#Python program to multiply two numbers using function
def multiply(a, b):#function for multiplication
    multiplication = a * b;
    return multiplication


num1 = int(input("Enter first number : "))
num2 = int(input("Enter second number : "))
print("The multiplication is", multiply(num1,num2))

Program 3

Again same program, the change is we accept floating point numbers and do the multiplication.


#Python program to multiple two numbers using function
#function for multiplication
def multiply_floats(a,b):
    multiploication = a * b;
    return multiplication


first_number = float(input("Enter first number : "))
second_number = float(input("Enter second number : "))
print("The multiplication is", multiply_floats(first_number , second_number))

Related Python Programs

Lists
What is maximum possible length of
What will be output of following python

Comments