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
Perform division of two numbers in C language|using 6ways

Python program to Divide two numbers|in 4ways

Posted on September 7, 2020September 9, 2020

Table of Contents

  • Python program to Divide two numbers
    • Program to Divide two numbers
      • Program to Divide two numbers-standard method
      • Program to Divide two numbers-using user input
      • Program to Divide two numbers-using function
      • Program to Divide two numbers-using recursion
    • Related

Python program to Divide two numbers

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

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

Program to Divide two numbers

Program to Divide two numbers-standard method

Program 1

num1=250
num2=25

div=num1/num2;

print("The division of {0} and {1} is: {2}".format(num1,num2,div))

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

The division of 250 and 25 is: 10

 

  • Integer variable num1 and num2 both are declared and initialized
  • the num1 and num2 both are divided together and the value assigned to the integer variable div
  • finally the program is displayed the output using print() function

 

Program to Divide two numbers-using user input

Program 2

num1=input("Enter the first number: ")
num2=input("Enter the second number: ")

div=num1/num2;

print("The division of {0} and {1} is: {2}".format(num1,num2,div))

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

Enter the first number: 2400
Enter the second number: 80
The division of 2400 and 80 is: 30

 

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 and num2
  • the program will read the input and store the variables in num1, num2.
  • the num1 and num2 both are divided together and the value assigned to the integer variable div
  • finally the program is displayed the output using print()

 

Program to Divide two numbers-using function

Program 3

#python program to divide two numbers using function
def divNum(a,b):#function definision for division
    divide=a/b
    return divide
num1=int(input("input the number 1 : "))#input from user to num1
num2=int(input("input the number 2 : ")) #input from user to num2

print("The division is",divNum(num1,num2))#call the function

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

input the number 1 : 450
input the number 2 : 30
The division is', 15

 

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 to find division of two numbers
  • When we call the function, the num1 and num2 both are divided together
  • Then the value is assigned to the integer variable result
  • finally the program is displayed the output using print() function

Program to Divide two numbers-using recursion

Program 4

#python program to divide two numbers using function
def divNum(x,y):#function definision for division
    if (y==0):
        return 0;
    elif (x-y==0):
        return 1;
    elif (x<y):
        return 0;

    else:
        return (1+divNum(x-y,y));

num1=int(input("input the number 1 : "))#input from user to num1
num2=int(input("input the number 2 : ")) #input from user to num2

print("The division is",divNum(num1,num2))#call the function

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

input the number 1 : 1000
input the number 2 : 40
('The division is', 25)

 

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

 

Suggested post

Function in Python language

Operator in Python language

Data type in Python

 

 

Similar post

C program to calculate division of two numbers | 6 different Methods

C++ program to calculate division of two numbers | 6 different Methods

Java program to calculate division of two numbers | 5 different Methods

 

 

 

Related

Recent Posts

  • Multiply two numbers in Java using scanner| 5 different ways
  • 5 different ways to Divide two numbers in Java using scanner
  • Learn 8 Ways to Subtract Two Numbers Using Methods in Java
  • 10 ways to subtract two numbers in Java
  • Java Code Examples – Multiply Two Numbers in 5 Easy Ways
  • How to Divide two numbers in Java| 5 different ways

tag

Addition (8) Array (38) C++ language (91) C language (98) c sharp (23) Division (8) Function (29) if else (32) Java language (108) JavaScript (5) loops (138) Multiply (8) Oop (2) patterns (66) PHP (13) Python Language (38) Subtraction (9) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2026 Code for Java c | Powered by SuperbThemes