Write a program to read two numbers and print their quotient and remainder in Python
In this exercise, 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.
Python Naive Method
In this method, first we take two inputs from the user using the input() function and store them in two variables, and then we obtain the quotient using division and the remainder using the modulus operator.
Output of the above code-
Enter the first number: 20
Enter the second number: 5
Quotient: 4
Remainder 0
Python divmod() method
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.
Output of the above code-
Enter the first number: 43
Enter the second number: 2
Quotient: 21
Remainder: 1
need an explanation for this answer? contact us directly to get an explanation for this answer