首页 > 解决方案 > 炮兵脚本的“TypeError:'float'对象不可调用”

问题描述

我决定尝试编写弹道计算机的代码。下面是我编写的代码,它获取目标的初速、距离和仰角,并输出所需的射击角度,以便发射的炮弹将在所需位置发生碰撞。目前我在倒数第二行遇到一个错误,我不知道如何修改这个错误。任何帮助将不胜感激。

import math
print("Note that the platform you are firing off must be perfectly flat to ensure optimal accuracy")
print("---------------------------------------------------------------")
g = (-9.81) **#g is negative in this case**

degrees = float(input("What is the angle from horizon of the spotter? [0-90] "))

radians = math.radians(degrees) **#Sin only works with radians**

U = float(input("What is the muzzle velocity of the gun? "))

Target_distance = float(input("What is the distance to the target in Meters? ")) #direct distance to target

y = float(math.sin(radians))**Target_distance #horizontal distance to target**

x = float(math.cos(radians))**Target_distance #elevation to target from you**

print("the elevation of the target is",y)

print("the distance to the targetenter code here is",x)

print("true distance to target is",Target_distance)


max_angle = math.radians(45)

max_dist = ((U**2)/(2*g))*(1+(math.sqrt(1+((2*g*y)/(U**2)*((math.sin(max_angle)*

(math.sin(max_angle)))))))*math.sin(max_angle))#shows the maximum distance of the shell being fired

print (("max gun range is"),-1*max_dist)

print("---------------------------------------------------------------")


theta = math.degrees((math.asin((g*x)/(U**2)))*-1) #equation needs to be halved to get correct solution

solution1 = (theta *0.5) 

solution2 = (90 - solution1)

print(solution1)

print(solution2)

print("---------------------------------------------------------------")

#issue here (TypeError 'float' object is not callable) - 传入的变量是 U,g,x,y

炮兵脚本的“TypeError:'float'对象不可调用”

solution_3 = math.degrees(math.atan((U*U) + (math.sqrt(U*U*U*U - g ( g * (x * x) + ( 2 * y * (U**2)))))) / ( g * x))

print (solution_3)

标签: pythonpython-3.6

解决方案


改用这个:

solution_3 = math.degrees(math.atan((U**2) + (math.sqrt(U**4 - g * ( g * (x * x) + ( 2 * y * (U**2)))))) / ( g * x))

g”后缺少*


推荐阅读