본문 바로가기
파이썬

파이썬 Typeerror int는 호출 할 수 없습니다.

by º기록 2020. 9. 14.
반응형

사용자가 입력 한 정보를 기반으로 단리를 계산하는 함수를 사용하는 프로그램을 작성하려고합니다. TypeError- 'int'는 호출 할 수 없습니다. 이 오류는 실수로 변수 이름을 int로 지정한 경우에만 발생한다고 생각했지만 그렇게하지 않았기 때문에 내 프로그램에서 이러한 유형의 오류가 발생하는 이유를 모르겠습니다. 코드는 다음과 같습니다. 모든 지침에 감사드립니다!

def accrued(p, r, n):
    percent = r/100
    total = p(1 + (percent*n))
    return total

principal = int(input('Enter the principal amount: '))
rate = float(input('Enter the anuual interest rate. Give it as a percentage: '))
num_years = int(input('Enter the number of years for the loan: '))
result = accrued(principal, rate, num_years)
print(result)

 

해결 방법

 

변화:

total = p(1 + (percent*n))

에:

total = p*(1 + (percent*n))

* 가 없으면 p (...) 는 함수 호출로 구문 분석됩니다. 정수가 p 로 전달되기 때문에 표시되는 오류가 발생합니다.

 

참조 페이지 https://stackoverflow.com/questions/63756593

 

 

반응형

댓글