class Solution(object):

```
def fractionToDecimal(self, n, d):
sign, p_int, point, p_frac, d, n, dic = "-"*(n*d<0), str(abs(n)//abs(d)), "."*(n%d!=0), "", abs(d), abs(n)%abs(d), []
while n not in dic and n!=0: dic, p_frac, n = dic+[n], p_frac+str(n*10//d), n*10%d
return sign+p_int+point+p_frac if n==0 else sign+p_int+point+p_frac[:dic.index(n)]+"("+p_frac[dic.index(n):]+")"
```

The result is segmented into "sign", "integer part", "point", "fractional part"

First line: initialize all parts, and convert inputs to positive numbers

Second line: update fractional part, with what you learned from elementary school

Third line: combine all parts, find the place to add "()"