私は学校プロジェクトのためにこのコードに助けが必要です。Python - TypeError:複合体を浮動小数点に変換できません
import math
v = 9.412
g = 9.81
y = -1.5
def radToDeg(x):
return((x/math.pi) * 180)
def sqrt(x):
return(x ** 0.5)
def CalculateAngle(x):
return(radToDeg(math.atan(((v ** 2) + (sqrt((v ** 4) - (g * ((g * x ** 2) + (2 * y * v ** 2))))))/(g * x))))
print(CalculateAngle(90.0297))
私はプログラムを実行すると、私はエラーが表示されます。
Traceback (most recent call last):
File "C:/Users/Owner/Desktop/ballista.py", line 16, in <module>
print(CalculateAngle(float(90.0297)))
File "C:/Users/Owner/Desktop/ballista.py", line 14, in CalculateAngle
return float(radToDeg(math.atan(((v ** 2) + (sqrt((v ** 4) - (g * ((g * x ** 2) + (2 * y * v ** 2))))))/(g * x))))
TypeError: can't convert complex to float
誰かが私はこの問題を解決する手助けすることはできますか?ありがとう!
あなたの関数が入力としてラジアンを受け入れるように設定されているようですが、あなたは度を渡しています... – mgilson