Mod Divmod in Python HackerRank Solution

Hello Programmers, In this post, you will know how to solve the Mod Divmod in Python HackerRank Solution. This problem is a part of the HackerRank Python Programming Series.

Mod Divmod in Python HackerRank Solution
Mod Divmod in Python HackerRank Solutions

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Hackerrank by yourself. If you find any difficulty after trying several times, then you can look for solutions.

Mod Divmod in Python HackerRank Solution


One of the built-in functions of Python is divmod, which takes two arguments a and b and returns a tuple containing the quotient of a/b first and then the remainder a.

For example:

>>> print divmod(177,10)
(17, 7)

Here, the integer division is 177/10 => 17 and the modulo operator is 177%10 => 7.

Task :

Read in two integers, a and b, and print three lines.
The first line is the integer division a//b (While using Python2 remember to import division from __future__).
The second line is the result of the modulo operator: a%b.
The third line prints the divmod of a and b.

Input Format :

The first line contains the first integer, a, and the second line contains the second integer, b.

Output Format :

Print the result as described above.

Sample Input :


Sample Output :

(17, 7)

Mod Divmod in Python HackerRank Solutions

# Enter your code here. Read input from STDIN. Print output to STDOUT
d = divmod(int(input()), int(input()))
print(*d, d, sep='\n')

Disclaimer: The above Problem (Mod Divmod in Python) is generated by Hackerrank but the Solution is Provided by BrokenProgrammers. This tutorial is only for Educational and Learning purposes.

Next: Power and Mod Power in Python HackerRank Solution

Leave a Reply

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