Floor Division vs True Division

Easy ⏱ 8 min 79% acceptance ★★★★★ 4.7
Write a function divide_both(a, b) that returns a tuple (true_division_result, floor_division_result) for a / b and a // b respectively, demonstrating the difference between / (always float) and // (rounds toward negative infinity).

Examples

Example 1
Input
divide_both(7, 2)
Output
(3.5, 3)
Explanation

7 / 2 = 3.5 (float); 7 // 2 = 3 (int floor).

Example 2
Input
divide_both(-7, 2)
Output
(-3.5, -4)
Explanation

Floor division rounds toward negative infinity, not toward zero.

Constraints

  • b is never 0.

Topics

Operatorsarithmetic operators

Companies

AmazonTCS

Hints

Hint 1

`/` always returns a float in Python 3.

Hint 2

`//` floors toward negative infinity, which differs from truncation for negative numbers.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.