python - 炮兵脚本的“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)
解决方案
改用这个:
solution_3 = math.degrees(math.atan((U**2) + (math.sqrt(U**4 - g * ( g * (x * x) + ( 2 * y * (U**2)))))) / ( g * x))
“ g”后缺少*
推荐阅读
- mysql - MySQL / MariaDB - 从数据库中删除除最后一条记录外的所有记录
- java - 如何使用卡片视图将数据从一项活动传输到另一项活动?
- nginx - Nginx缓存第一个浏览器请求总是Miss
- c++ - 这段代码是如何工作的?关于指针,字符串文字
- yaml - GCP/GKE 添加网络标签
- javascript - 按字符对字符串数组进行排序并返回所有匹配的元素
- c - 混合 c 和组装 cortex-m0
- python - 销毁 tkinter 标签
- c - 可以在 printf 中给 %c 一个负的 int 参数吗?
- javascript - 当我刷新页面时重复 javascript 内容消失。我该如何解决?