Problem
Link to the original HackerRank problem
Task
The provided code stub reads two integers,
a
andb
, 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.
Example
a = 3
b = 5
- The result of the integer division
3 // 5 = 0
.- The result of the integer division
3 / 5 = 0.6
.Print:
0 0.6
Input Format
The first line contains the first integer,
a
.The second line contains the first integer,
b
.Output Format
Print the three lines as explained above,
Sample Input 0
4 3
Sample Output 0
1 1.33333333333
Code
Starter
if __name__ == '__main__':
a = int(input())
b = int(input())
Solution
Straightforward
If we translate 1:1 the instructions given in the Problem section, we can quickly write each operation as a simple as-is statement in Python:
if __name__ == '__main__':
a = int(input())
b = int(input())
print(a // b)
print(a / b)
One-liner
Or as a simple one-liner, leveraging the sep
parameter of the print
function:
if __name__ == '__main__':
a = int(input())
b = int(input())
print(a // b, a / b, sep="\n")