Python Program to Read Two Numbers and Print Their Quotient and Remainder


When it is required to read two numbers and print the quotient and remainder when they are divided, the ‘//’ and ‘%’ operators can be used.

Below is a demonstration of the same −

Example

 Live Demo

first_num = int(input("Enter the first number..."))
second_num = int(input("Enter the second number..."))
print("The first number is ")
print(first_num)
print("The second number is ")
print(second_num)
quotient_val = first_num//second_num
remainder_val = first_num%second_num

print("The quotient is :")
print(quotient_val)
print("The remainder is :")
print(remainder_val)

Output

Enter the first number...44
Enter the second number...56
The first number is
44
The second number is
56
The quotient is :
0
The remainder is :
44

Explanation

  • The first and second numbers are taken as input from the user.

  • They are displayed on the console.

  • To find the quotient, the ‘//’ operator is used.

  • To find the remainder, the ‘%’ operator is used.

  • The operations output is assigned to two variables respectively.

  • This is displayed as output on the console.

Updated on: 16-Apr-2021

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements