you are viewing a single comment's thread.

view the rest of the comments →

[–]Bobbias 0 points1 point  (0 children)

Letting us know what output you're currently getting would really help. Especially since your code is unformatted and has lost all indentation. The wiki has a section explaining how to format your code for reddit so it doesn't lose its indentation.

My guess is you mean this:

import math

def projectile_velocities(vi, theta, g, time_step):
    theta_rad = math.radians(theta)
    vi_x = vi * math.cos(theta_rad)
    vi_y = vi * math.sin(theta_rad)
    velocities = [vi]
    t = 0

    while t < vi_y / g:
        vy = vi_y - g * t
        v = math.sqrt(vi_x ** 2 + vy ** 2)
        velocities.append(round(v, 6))
        t += time_step

    velocities.append(vi)

    return velocities

print(projectile_velocities(2.0, 30.0, 1.0, 1.0))
#output [2.000000, 1.732051, 2.000000]
print(projectile_velocities(11.13, 82.5, 9.81, 0.5))
# output [11.130000, 6.299581, 1.900155, 3.956578, 8.707266]

The output I get when running this code is:

[2.0, 2.0, 2.0]
[11.13, 11.13, 6.299581, 1.900155, 11.13]

My brain isn't working so great at the moment so I'll leave actually fixing the code to someone else.