• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / Python / Find Quotient and Remainder After Division in Python

Find Quotient and Remainder After Division in Python

June 5, 2022 Leave a Comment

To get the quotient and remainder after division of two numbers in Python, the easiest way is with the Python divmod() function.

print(divmod(10,3))

#Output:
(3, 1) 

You can also create your own function and use integer division and the % operator to get the quotient and remainder afster division.

def quo_rem(a,b):
    return a // b, a % b

print(quo_rem(10,3))

#Output:
(3, 1) 

When performing different calculations with numbers in Python, the ability to easily get certain pieces of information about the calculation can be useful.

One such case is when dividing by two numbers in Python. We can easily get the quotient and remainder after division in Python.

To get the quotient and remainder after division of two numbers in Python, the easiest way is with the Python divmod() function.

The Python divmod() function takes two arguments – the two numbers you want to divide, and returns a tuple with the first element being the quotient and the second element being the remainder.

Below is an example showing you how to use divmod() to get a quotient and remainder from two numbers in Python.

print(divmod(10,3))

#Output:
(3, 1) 

You can then verify these are the correct values by multiplying the first returned element by the second parameter and adding the second returned element.

res = divmod(10,3)

print(res[0] * 3 + res[1])

#Output:
10

Getting Quotient and Remainder after Division Using Integer Division and %

You can also write your own function which will calculate the quotient and remainder for you using integer division and the % operator.

With integer division, you will get the quotient and with %, you will get the remainder.

Below is a function which can return the quotient and remainder after the division of two integers with Python.

def quo_rem(a,b):
    return a // b, a % b

print(quo_rem(10,3))

#Output:
(3, 1)

Hopefully this article has been useful for you to learn how to get the quotient and remainder after division of two numbers in Python.

Other Articles You'll Also Like:

  • 1.  Find Maximum of Three Numbers in Python
  • 2.  Python Delete Variable – How to Delete Variables with del Keyword
  • 3.  Python Even or Odd – Check if Number is Even or Odd Using % Operator
  • 4.  Sign Function in Python – Get Sign of Number
  • 5.  Convert String to Integer with int() in Python
  • 6.  Sorting with Lambda Functions in Python
  • 7.  Python Remove First Element from List
  • 8.  Using Python to Compare Strings Alphabetically
  • 9.  Check if Variable is Tuple in Python
  • 10.  Using Python to Replace Multiple Spaces with One Space in String

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy