0

I am working on python code and I was trying to calculate distance of an object if the height , angle and original velocity was given. this was my code. It doesn't work it gives me an error message every time.

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

Please Help

GNY
  • 39
  • 6
  • You havn't defined `angle`, `height` and `speed` – kuro Apr 04 '17 at 07:47
  • what error does it give you? please provide. – Alex L Apr 04 '17 at 07:57
  • Add enough code so your snippet can be run. Also give the entire traceback for the error that results from your snippet. See [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). Also, define your terms "height , angle and original velocity" more precisely. – Rory Daulton Apr 04 '17 at 07:58

1 Answers1

0

You try block should be like this:

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

and be carefoul that ^ is not the exponent operator in python, use ** instead:

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)))
lch
  • 2,028
  • 2
  • 25
  • 46