Write a program to read two numbers and print their quotient and remainder in Python
In this post, we will write a simple Python program that takes input from the user and calculates the quotient and remainder operation. There are different ways to achieve this task. Here, we are mentioning two ways to read two numbers and print their quotient and remainder in Python. The quotient is the result of the division, while the remainder is the value remaining after the division.
In this method, first we take two inputs from the user using input() function and store them in two variables and then obtain the quotient using division and the remainder using modulus operator.
Output of the above code -
# Get quotient and remainder # using Python program def find(n, m): # for quotient q = n//m print("Quotient: ", q) # for remainder r = n%m print("Remainder", r) # User Input a=int(input("Enter the first number: ")) b=int(input("Enter the second number: ")) find(a,b)
The divmod() function takes two numbers and returns a tuple containing the quotient and the remainder.Syntax -
Here, the divident is the number you want to divide and the divisor is the number you want to divide with.
a Output of the above code -
# Get quotient and remainder # using Python program # Get user inputs a=int(input("Enter the first number: ")) b=int(input("Enter the second number: ")) q, r = divmod(a,b) print("Quotient: ", q) print("Remainder: ", r)
Program to calculate simple interest in Python
Program to find area of triangle in Python
Python program to multiply two numbers
Python projects for beginners
Find average of n numbers in Python
Reverse pyramid pattern in Python
Stemming and Lemmatization in Python
Python program to convert decimal to binary
Print multiplication table in Python
Fibonacci Series In Python | Python Program To Print
File Handling in Python
How to convert XML to JSON in Python
Python XML to Dictionary
Python program to multiply two matrices