Hi guys,

So I recently started coding in Python and I’m writing a projectile motion calculator. The algebraic component is working but I can’t figure out a way of inputing variables to be used in the above formulas. My code is attached below.

Thanks!

from math import sin

from math import pi

from math import sqrt

from math import radians

from math import cos

def max_height(angle, v_0, y_0):

angle = radians(angle)

return ((v_0 ** 2 * (sin(angle)) ** 2 / 9.81 * 2) + y_0)

def time_of_flight(angle, v_0, y_0):

time_of_flight = v_0 * sin(angle)

time_of_flight = time_of_flight + sqrt(v_0 ** 2 * (sin(angle)) ** 2 + 19.62 * y_0)

time_of_flight = time_of_flight / 9.81

return time_of_flight

def time_to_peak(angle, v_0):

angle = radians(angle)

return (v_0 * sin(angle)) / 9.81

def range_x(angle, v_0, y_0, x_0):

angle = radians(angle)

return x_0 + v_0 * cos(angle) * time_of_flight(angle, v_0, y_0)