Python divmod() function

Published February 15, 2022

If you would like to write a small mathematical Python program that divides two integers, verifies divisibility, or checks whether a number is prime or not, and returns the quotient and remainder, you'll need to implement the divmod() function. The divmod() method is a standard Python library function that takes two integers or variables as input and returns a tuple containing the remainder and quotient of their division.

Syntax

divmod(num1, num2)

Where, num1 and num2 : num2 divides num1

Num1 and num2 can either be integers or floats

Example

In this example, we will test the divisibility of two integers and two floats.

# integers

print("7 divide by 3:",divmod(7,3))

print("1000 divide by 10:",divmod(1000,10))

# Floats

print("11.5 divide by 3 give:",divmod(11.5,3))

print("19.78 divide by 5.2 give:",divmod(19.78,5.2))

Output

 

divmod()-function-example

 

Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

297 Views