Find Recurring Sequence in a Fraction | This function returns repeating sequence of a fraction . If repeating sequence doesn 't exits, then returns empty string ; Initialize result ; Create a map to store already seen remainders . Remainder is used as key and its position in result is stored as value . Note that we need position for cases like 1 / 6. In this case , the recurring sequence doesn 't start  from first remainder. ; Find first remainder ; Keep finding remainder until either remainder becomes 0 or repeats ; Store this remainder ; Multiply remainder with 10 ; Append rem / denr to result ; Update remainder ; Driver code
def fractionToDecimal ( numr , denr ) : NEW_LINE INDENT res = " " NEW_LINE mp = { } NEW_LINE rem = numr % denr NEW_LINE while ( ( rem != 0 ) and ( rem not in mp ) ) : NEW_LINE INDENT mp [ rem ] = len ( res ) NEW_LINE rem = rem * 10 NEW_LINE res_part = rem // denr NEW_LINE res += str ( res_part ) NEW_LINE rem = rem % denr NEW_LINE DEDENT if ( rem == 0 ) : NEW_LINE INDENT return " " NEW_LINE DEDENT else : NEW_LINE INDENT return res [ mp [ rem ] : ] NEW_LINE DEDENT DEDENT numr , denr = 50 , 22 NEW_LINE res = fractionToDecimal ( numr , denr ) NEW_LINE if ( res == " " ) : NEW_LINE INDENT print ( " No ▁ recurring ▁ sequence " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Recurring ▁ sequence ▁ is " , res ) NEW_LINE DEDENT