import math h= raw_input("input Height") #maximum hight a= raw_input("input Angle") #angle v= raw_input("input Initial Velocity") #initial velocity t= raw_input("input Time") #total time r= raw_input("input Range") #range vx= "" # horizontal velocity vy= "" # vertical velocity g = 9.81 # gravity constant def height(): # checks if the hihgt varialbe is empty and if so, it calculates it global a #imorts all of the globals into function global v global t global r global vx global vy global g global h if h == "" and r != "" and a != "": # if we have range and angle values, it calculates height a_rad = float(a) * math.pi / 180 #1 Converting a - angle in degrees into a_rad - angle in radians h = float(r) * math.tan(a_rad) / 4 elif h == "" and v != "" and a != "": # if we have initial velocity and angle values, it calculates height a_rad = float(a) * math.pi / 180 #2 Converting a - angle in degrees into a_rad - angle in radians vy = float(v) * math.sin(a_rad) # using initialvelocity magnitude we clculate horizontal velocity - vy h = vy**2 / (2 * g) # calculates hight elif h == "" and t != "": # if we have time value, it calculates height h = g * (float(t)/2)**2 / 2 def initial_velocity(): global v # Imports all of the globals into the function global t global a global r global vx global vy global g if v == "" and r != "" and t != "": # If we have range and time values, we can find initial velocity vx = float(r)/float(t) # Calculates horizontal initial velocity vy = g*(float(t)/2) # Calculates vertical initial velocity v = math.sqrt(vx**2 + vy**2) # Calculates Initial velocity elif v == "" and h != "" and a != "": a_rad = float(a)*math.pi/180 v = math.sqrt((2*g*float(h))/(math.sin(a_rad)**2)) elif v == "" and r != "" and a != "": a_rad = float(a)*math.pi/180 v = math.sqrt((float(r)*g)/(2*math.sin(a_rad)*math.sin(a))) def distance(): #if the distance variable is empty, then the program will calculate it. global h global r global t global a global v global r global vx global vy if r== '' and v != '' and a != '': #if we have the velocity and the angle, we can find the range. a_rad = float(a) * math.pi/180 r = (float(v)**2/g)*(2*math.sin(a_rad)*math.cos(a_rad)) elif r == '' and v != '' and t != '' and a != '': a_rad = float(a) * math.pi/180 vx = float(v)*math.cos(a_rad) r = vx * t elif r == '' and a != '' and h != '': a_rad = float(a) * math.pi/180 r = 4*h/math.tan(a) def time(): #The function for finding flight time global a global v global h global t global r global g if t=="" and a != "" and v != "": #first condition a_rad= float(a)*math.pi/180 v= float(v) t= (2*v*math.sin(a_rad))/g elif t=="" and h != "": #second condition h=float(h) t= 4*h/math.sqrt(2*g*h) elif t=="" and r != "" and a != "": r=float(r) a=float(a) t= (2*r*math.tan(a_rad))/math.sqrt(2*g*r*math.tan(a_rad)) def angle(): global h global r global t global a global v global g if a == "" and r != "" and v != "": # if we have range and angle values, it calculates height r=float(r) v=float(v) a= 0.5*(math.degrees(math.asin((r*g)/v**2))) # caculate the value of angle in degree angle=1/2*(arc sin(r*g)/v2)) #def reset(): def check(): if (v=="" or r=="" or h==""or a=="" or t=="") and (): return True floating_list() else: return False def floating: global h global r global t global a global v global g floating_list=[h,t,v,r,a] for x in floating_list: if x.isdigit() == True x = float(x) print type(h) else: print 'Input a number!' def calculate(): floating() while check(): time() height() initial_velocity() distance() angle() else: print a print h print r print v print t calculate()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question