Count number of digits after decimal on dividing a number | Python3 program to count digits after dot when a number is divided by another . ; ans = 0 Initialize result ; calculating remainder ; if this remainder appeared before then the numbers are irrational and would not converge to a solution the digits after decimal will be infinite ; Driver Code
def count ( x , y ) : NEW_LINE INDENT m = dict ( ) NEW_LINE while x % y != 0 : NEW_LINE INDENT x %= y NEW_LINE ans += 1 NEW_LINE if x in m : NEW_LINE INDENT return - 1 NEW_LINE DEDENT m [ x ] = 1 NEW_LINE x *= 10 NEW_LINE DEDENT return ans NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT res = count ( 1 , 2 ) NEW_LINE print ( " INF " ) if res == - 1 else print ( res ) NEW_LINE res = count ( 5 , 3 ) NEW_LINE print ( " INF " ) if res == - 1 else print ( res ) NEW_LINE res = count ( 3 , 5 ) NEW_LINE print ( " INF " ) if res == - 1 else print ( res ) NEW_LINE DEDENT