Coding/Python 삽질기2016. 9. 7. 02:42
def getDecimal(q, size):
    
    if (q < 2):
        return -1
    
    p = 10
    result = "0."
    
    for i in range(size):
        m = p % q
        
        result += str(int(p / q))
        if (m == 0):
            break;
        else:
            p = m * 10
    
    return result
    

    
for i in range(2, 10):
    print(str(i) + " : " + getDecimal(i, 100) )


2 : 0.5

3 : 0.3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333

4 : 0.25

5 : 0.2

6 : 0.1666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666

7 : 0.1428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428

8 : 0.125

9 : 0.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111

'Coding > Python 삽질기' 카테고리의 다른 글

[Python] 진법 변환  (0) 2016.12.27
[Notepad++] Python 실행하기  (0) 2016.08.28
Cython 설치  (4) 2013.12.15
Posted by chobocho