Rational Number

Published by BlackJack007 in

Declare a Rational() function that gets two natural numbers (a, b) and return a string containing a record of the rational number a / b in the form of a decimal fraction, possibly periodic.

Examples

Rational(2, 5) ➞ "0.4"

Rational(1, 6) ➞ "0.1(6)"

Rational(1, 3) ➞ "0.(3)"

Rational(1, 7) ➞ "0.(142857)"

Rational(1, 77) ➞ "0.(012987)"

Notes

  • Always a < b.
  • The length of a periodic fraction can be more than 20 numbers.
  • You can find a hint in the Comments.
Watch a quick demo on how Edabit works.