Python Division – HackerRank Solution

Python Division

The provided code stub reads two integers, a and,b from STDIN.

Add logic to print two lines. The first line should contain the result of integer division, a//b. The second line should contain the result of float division, a/b.

No rounding or formatting is necessary.



The result of the integer division is 3//5=0.
The result of the float division is 3/5=0.6.


Input Format

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

Output Format

Print the two lines as described above.

Sample Input 0

Sample Output 0



if __name__ == '__main__':
    a = int(input())
    b = int(input())

This is a Python program that takes two integers as input and performs division on them. It is a solution to the “Python: Division” problem on Hackerrank.

The program first reads in two integers a and b using the input() function and converts them to integers using the int() function.

The program then performs integer division of a by b using the / operator and the int() function. This will give the quotient of the division as an integer, with any fractional part truncated.

The program then performs float division of a by b using the / operator. This will give the quotient of the division as a floating-point number.

Finally, the program prints the integer quotient and the floating-point quotient on separate lines using the print() function and the int() and float() functions.

The purpose of this program is to demonstrate the difference between integer division and float division in Python. Integer division returns an integer quotient, while float division returns a floating-point quotient.

Disclaimer: These problems are originally created and published by HackerRank, we only provide solutions to those problems.Hence, doesn’t guarantee the truthfulness of the problem. This is only for information purposes.

Leave a Comment