테일러 함수 명령문 오류

조회수 1240회

import math

class tail: def facto(a):

    fac = 1

    if a == 0:

        fac == 1

    else:

        while a != 1:

            fac = (fac * a)

            a -= 1

    return fac


def asd(i):

    if (i % 2) == 0:

        a = 1

    else:

        a = -1

    return a


def sin(x,i):

    a = 0

    res = 0

    while a != i :

        res = res  + tail.asd(a)*(x**(2*(a+1)-1)/tail.facto(2*(a+1)-1))    

        a += 1
    return res

def cos(x,i):

    a = 0

    res = 0


    while a != i :

        res = res  + tail.asd(a)*(x**(2*(a+1)-2)/tail.facto(2*(a+1)-2))    

        a += 1
    return res

def cal(dif):
    start = 1
    while abs(abs(math.sin(math.pi * 0.1)) - abs(tail.sin(math.pi * 0.1, start))) > dif:

        start += 1

    print("sin 의 경우"+str(start)+"번쨰 부터 오차가 " + str(dif) + " 이하로 떨어짐")


    start = 1
    while abs(abs(math.cos(math.pi * 0.1)) - abs(tail.cos(math.pi * 0.1, start))) > dif:

        start += 1

    print("cos 의 경우"+str(start)+"번째 부터 오차가 " + str(dif) + " 이하로 떨어짐")
##### main

dif = 0.0001

tail.cal(dif)

오류는 아래와 같은 오류가 발생합니다.

Traceback (most recent call last): File "/solution.py", line 87, in tail.cal(dif) TypeError: unbound method cal() must be called with tail instance as first argument (got float instance instead)

  • (•́ ✖ •̀)
    알 수 없는 사용자

1 답변

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)