Table of Contents
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
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