Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
School solution in Clear category for Repeating Decimals by veky
def convert(numerator, denominator):
whole, rest = divmod(numerator, denominator)
before, after, mods = str(whole) + ".", "", [rest]
while True:
current, rest = divmod(rest * 10, denominator)
after += str(current)
if not rest: return (before + after).rstrip("0")
try: i = mods.index(rest)
except ValueError: mods.append(rest)
else: return before + after[:i] + after[i:].join("()")
Sept. 18, 2014
Comments: