【发布时间】:2017-08-29 07:07:11
【问题描述】:
我正在编写 python 代码,如果给出了高度、角度和原始速度,我正在尝试计算物体的距离。这是我的代码。它不起作用,每次都会给我一条错误消息。
import subprocess as sp
import math
sp.call('cls',shell=True)
pangle = float(0.0)
distance = float(0)
a = float(0)
y = float(0)
v = float(0)
a = input("Angle:")
y = input("Hight (Meter):")
v = input("Speed (M/S):")
try:
a = float(angle)
y = float(hight)
v = float(speed)
except:
sp.call('cls',shell=True)
print("Error")
error = input("")
exit
distance = float((v * (math.cos(math.radians(a/1))))*(v * math.sin(math.radians(a)) + ((v * math.sin(math.radians(a)))^2+2*y)**(1.0/2)))
sdistance = str(distance)
print ("Distance is " + sdistance + " Meter")
error = input("")
exit
请帮忙
【问题讨论】:
-
你还没有定义
angle、height和speed -
它会给你什么错误?请提供。
-
添加足够的代码,以便您的 sn-p 可以运行。还要为您的 sn-p 导致的错误提供整个回溯。见How to create a Minimal, Complete, and Verifiable example。此外,更准确地定义您的术语“高度、角度和原始速度”。
标签: python math distance trigonometry computation