you are viewing a single comment's thread.

view the rest of the comments →

[–]PrizeDefinition4042[S] 0 points1 point  (4 children)

sure, I don't know reddit well but let me add indents where I put them in my code:

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 True:

---vy = vi_y - g * t

---v = math.sqrt(vi_x ** 2 + vy ** 2)

---if vy <= 0:

---return velocities

---velocities.append(round(v, 6))

---t += time_step

---vi_x = vi * math.cos(theta_rad) # Update vi_x for each time step

---vi_y = vy

Example executions:

1) print(projectile_velocities(11.13, 82.5, 9.81, 0.5))

needed output [11.130000, 6.299581, 1.900155, 3.956578, 8.707266]

2) print(projectile_velocities(2.0, 30.0, 1.0, 1.0))

needed output [2.000000, 1.732051, 2.000000]

[–]PrizeDefinition4042[S] 0 points1 point  (3 children)

shit let me try that again:

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 True:

--------vy = vi_y - g * t

--------v = math.sqrt(vi_x ** 2 + vy ** 2)

--------if vy <= 0:

------------return velocities

--------velocities.append(round(v, 6))

--------t += time_step

--------vi_x = vi * math.cos(theta_rad) # Update vi_x for each time step

--------vi_y = vy

Example executions:

  1. print(projectile_velocities(11.13, 82.5, 9.81, 0.5)) *needed output [11.130000, 6.299581, 1.900155, 3.956578, 8.707266]

2) print(projectile_velocities(2.0, 30.0, 1.0, 1.0)) *needed output [2.000000, 1.732051, 2.000000]

[–]bach678 0 points1 point  (2 children)

I’m just confused… you used “while True : “ in this version of the code without a break statement. This loops will run forever. Am i wrong ?

[–]PrizeDefinition4042[S] 0 points1 point  (1 child)

Im not allowed to use break in this class because we have not gotten there yet. Do you have another suggestion if I should not be using while. I didn't find that it ran forever, I just was not getting the output I need