2017-04-04 90 views
0

我正在处理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 

请帮助

+0

你没有定义'angle','height'和'speed' – kuro

+0

什么错误会给你带来什么?请提供。 –

+0

添加足够的代码,以便您的代码段可以运行。同时给出你的代码片段导致的错误的全部回溯。请参见[如何创建最小,完整和可验证示例](http://stackoverflow.com/help/mcve)。此外,更准确地定义您的术语“高度,角度和原始速度”。 –

回答

0

您尝试块应该是这样的:

try: 
    a = float(a) 
    y = float(y) 
    v = float(v) 

,并carefoul是^是不是在蟒蛇的指数运算符,使用**代替:

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)))