Arithmetic Caculation

Python Program to Compute Quotient and Remainder

Python Program to Compute Quotient and Remainder

In this tutorial, we will discuss the Python Program to Compute Quotient and Remainder

In this post, we are going to learn how to find quotient and remainder of two numbers using different 3 ways in python.

 

Program to Compute Quotient and Remainder – standard method

Program 1

dividend=30
divisor=4
quotient=dividend//divisor;
remainder=dividend%divisor;
print("Quotient is: ",quotient)
print("remainder is: ",remainder)

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

Quotient is: 7
remainder is: 2

 

In this program,

  • integer variables dividend and divisor are declared and initialized
  • integer variables quotient and remainder are declared.
  • The dividend and divisor both are used to calculate quotient and remainder
  • Then,the program is displayed the output of using print() function.

 

Program to Compute Quotient and Remainder -using  user input

Program 2

dividend=int(input("Enter the dividend: "))
divisor=int(input("Enter the divisor: "))
quotient=dividend//divisor;
remainder=dividend%divisor;
print("Quotient is: ",quotient)
print("remainder is: ",remainder)

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

Enter the dividend: 200
Enter the divisor: 30
Quotient is: 6
remainder is: 20

 

  • integer variables dividend and ,divisor are declared
  • integer variables quotient and remainder are declared.
  • The program asks input from the user
  • Then the user enters the input values for dividend and divisor.
  • The program will read the input using input stream and store the variables dividend and divisor respectively
  • The dividend and divisor both are used to calculate quotient and remainder.
  • Then,the program is displayed the output of using printf() function

 

Program to Compute Quotient and Remainder -using  function

Program 3

dividend=int(input("Enter the dividend: "))
divisor=int(input("Enter the divisor: "))

def quotient(dividend,divisor):
    return dividend/divisor;

def remainder(dividend,divisor):
     return dividend%divisor;



print("Quotient is: ",quotient(dividend,divisor))
print("remainder is: ",remainder(dividend,divisor))

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

Enter the dividend: 23
Enter the divisor: 3
('Quotient is: ', 7)
('remainder is: ', 2)

 

Approach

  • Integer variable dividend and ,divisor both are declared,
  • The program takes input from the user
  • Then the user enters the input value for dividend and ,divisor
  • The program will read the input value and store the variables in  dividend and divisor.
  • Define the two function for finding quotient and remainder , separately
  • When we call the function, The dividend and divisor both are used to calculate quotient and remainder.
  • Finally the program is displayed the output using print() function.

 

Program 4

#Python program to find quotient and remainder using function
dividend=999
#Variable Declare and initilaize for dividend
divisor=49
#Variable Declare and initilaize for divisor

def quotient(dividend,divisor):
    result= dividend/divisor;
    print("Quotient is: ",result)
#function for find quotient

def remainder(dividend,divisor):
     result= dividend%divisor;
     print("Remainder is: ",result)
#function for find remainder



quotient(dividend,divisor)
#calling the function for display quotient
remainder(dividend,divisor)
#calling the function for display remainder

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

(‘Quotient is: ‘, 20)
(‘Remainder is: ‘, 19)

 

Program 5

#Python program to find quotient and remainder using function
dividend=int(input("Enter the dividend: "))
#Ask input from the user and store the input in dividend variable
divisor=int(input("Enter the divisor: "))
#Ask input from the user and store the input in divisor variable

def quotient(dividend,divisor):
    result= dividend/divisor;
    print("Quotient is: ",result)
#function for find quotient

def remainder(dividend,divisor):
     result= dividend%divisor;
     print("Remainder is: ",result)
#function for find remainder



quotient(dividend,divisor)
#calling the function for display quotient
remainder(dividend,divisor)
#calling the function for display remainder'''



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

Enter the dividend: 2000
Enter the divisor: 100
(‘Quotient is: ‘, 20)
(‘Remainder is: ‘, 0)

 

 

Suggested post

Function in Python language

Operator in Python language

Data type in Python

 

Similar post

Java Program to Compute Quotient and Remainder

C++ Program to Compute Quotient and Remainder

C Program to Compute Quotient and Remainder

 

Java Program to divide two numbers

C Program to divide two numbers

C++ Program to divide two numbers

Python Program to divide two numbers

Karmehavannan

Recent Posts

Subtract two numbers using method overriding

Subtract two numbers using method overriding   Program 1

3 months ago

PHP Star triangle Pattern program

PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…

3 months ago

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

1 year ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

1 year ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

1 year ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

1 year ago

This website uses cookies.