물리 방정식을 풀기 위해 개인적인 용도로 스크립트를 만들었습니다. 나는 파이썬 멍청이이며 이것은 내 기술을 사용하고 언어에 대해 더 많이 배우려는 시도입니다. 그러나 변수에 값을 입력하지 않으면 스크립트가 해당 변수를 해결하도록 지시됩니다. 이것은 제목에 주어진 오류를 뱉어내는 내 'accel'변수를 제외한 모든 변수에서 작동합니다. 스크립트가 중단되고 다음 줄에서 오류가 발생합니다.
accel = ((2(x - x0 - (v0 * t))) / (t ** 2))
어떤 도움을 주시면 감사하겠습니다. 내가 가져 오는 이차 공식 스크립트는이 오류에 영향을주지 않아야합니다. 가져 오기를 주석 처리 할 때 동일한 오류가 발생하므로 해당 코드를 게시해야하는지 알려주기 때문입니다. 예, 비슷한 질문을 살펴 보았지만 도움이되지 않았습니다.
__author__ = '[PDMC] Jeteroll'
import Quadratic_Formula
def dist():
print 'Enter the values for the following variables. Leave the variable blank for the value you wish to solve for.'
while True:
try:
x = float(raw_input('Value of x (final distance): '))
except ValueError:
solve_for = 'x'
print 'Will solve for x'
break
while True:
try:
x0 = float(raw_input('Value of x0 (initial distance): '))
except ValueError:
solve_for = 'x0'
print 'Will solve for x0'
break
while True:
try:
v0 = float(raw_input('Value of v0 (initial velocity): '))
except ValueError:
solve_for = 'v0'
print 'Will solve for v0'
break
while True:
try:
t = float(raw_input('Value of t (time): '))
except ValueError:
solve_for = 't'
print 'Will solve for t'
break
while True:
try:
accel = float(raw_input('Value of a (acceleration): '))
except ValueError:
solve_for = 'accel'
print 'Will solve for a'
break
if solve_for == 'x':
x = (x0 + ( v0 * t) + (.5 * accel * (t ** 2)))
print 'The value of x is: %s' % (round(x,2))
elif solve_for == 'x0':
x0 = (-((v0 * t) + (.5 * accel * (t ** 2)) - x))
print 'The value of x0 is: %s' % (round(x0,2))
elif solve_for == 'v0':
v0 = ((x - x0 - (.5 * accel * (t ** 2))) / t)
print 'The value of v0 is: %s' % (round(v0, 2))
elif solve_for == 't':
quad_a = (.5 * accel)
quad_b = (v0)
quad_c = (x0 - x)
t1, t2 = Quadratic_Formula.main(quad_a, quad_b, quad_c)
print 'The values of t are: %s, and %s' % (t1, t2)
elif solve_for == 'accel':
accel = ((2(x - x0 - (v0 * t))) / (t ** 2))
print 'The value of v0 is: %s' % (round(accel, 2))
else:
print 'You did not specify a variable to solve for'
dist()
if __name__ == '__main__':
dist()
문제는 다음과 같습니다.
accel = ((2(x - x0 - (v0 * t))) / (t ** 2))
다음과 같아야합니다.
accel = ((2 * (x - x0 - (v0 * t))) / (t ** 2))
기본적으로를 수행 2(...)
하여 Python에라는 함수를 찾아 호출하도록 요청했습니다 2
. 그러나 2
함수가 아니라 숫자입니다! 당연히 일이 깨졌습니다.
오류 메시지는 무엇이 잘못되었는지에 대한 힌트를 제공합니다. 오류 메시지는 int is not callable
-그것은 당신이 어떤 것을 실제로 함수 가 아닌 함수로 취급하고 있다는 것을 의미했습니다 . 거기에서 문제가 된 줄을 스캔하여 무엇이 잘못되었는지 찾기가 매우 쉬웠습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다