Numbers and bits · 15 / 15 Exercise Medium

Exact sum of fractions

Objective

With Fraction from the fractions module, operations with fractions are exact, without the rounding errors of float. The result comes already simplified.

Instructions

  • The first line has the number n of fractions; then one per line in the form a/b (or an integer).
  • Show the simplified sum. If it is not an integer, show its decimal value with 4 decimals on a second line.
Input
3
1/2
1/3
1/6
Output
1

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise