def dec_a_oct(n): ans = 0 i = 0 while n: ans += (n % 8) * (10 ** i) n = n / 8 i += 1 return ans print dec_a_oct(122)