Tell us what’s happening:
even if i have done every thing thing does not pass
import math
GRAVITATIONAL_ACCELERATION = 9.81
PROJECTILE = “∙”
x_axis_tick = “T”
y_axis_tick = “⊣”
class Projectile:
slots = (“__speed”, “__height”, “__angle”)
def __init__(self, speed, height, angle):
self.__speed = speed
self.__height = height
self.__angle = math.radians(angle)
@property
def speed(self):
return self.__speed
@speed.setter
def speed(self, new_speed):
self.__speed = new_speed
@property
def height(self):
return self.__height
@height.setter
def height(self, new_height):
self.__height = new_height
@property
def angle(self):
return round(math.degrees(self.__angle))
@angle.setter
def angle(self, new_angle_degrees):
self.__angle = math.radians(new_angle_degrees)
def __calculate_displacement(self):
v = self.__speed
h = self.__height
theta = self.__angle
g = GRAVITATIONAL_ACCELERATION
term_under_sqrt = (v**2 * (math.sin(theta))**2) + (2 * g * h)
sqrt_part = math.sqrt(term_under_sqrt)
numerator_part = (v * math.sin(theta)) + sqrt_part
displacement = (v * math.cos(theta) * numerator_part) / g
return displacement
def __calculate_y_coordinate(self, x):
y0 = self.__height
v0 = self.__speed
theta = self.__angle
g = GRAVITATIONAL_ACCELERATION
y = y0 + (x * math.tan(theta)) - ((g * x**2) / (2 * v0**2 * (math.cos(theta))**2))
return y
def calculate_all_coordinates(self):
coordinates_list = []
displacement = self.__calculate_displacement()
max_x = math.ceil(displacement)
for x in range(max_x):
y = self.__calculate_y_coordinate(x)
coordinates_list.append((x, y))
return coordinates_list
def __str__(self):
speed_val = self.speed
height_val = self.height
angle_degrees = self.angle
displacement_val = self.__calculate_displacement()
return (
f"\n"
f"Projectile details:\n"
f"speed: {speed_val} m/s\n"
f"height: {height_val} m\n"
f"angle: {angle_degrees}°\n"
f"displacement: {displacement_val:.1f} m\n"
)
def __repr__(self):
return f"Projectile({self.speed}, {self.height}, {self.angle})"
ball = Projectile(10, 3, 45)
coordinates = ball.calculate_all_coordinates()
print(ball)
class Graph:
slots = [‘__coordinates’]
def __init__(self, coordinates):
self.__coordinates = coordinates
def __repr__(self):
return f"Graph({self.__coordinates!r})"
def create_coordinates_table(self):
table_string = "\n"
table_string += f" {'x':>3}{'y':>7}\n"
for x_coord, y_coord in self.__coordinates:
table_string += f" {x_coord:>3}{y_coord:>7.2f}\n"
return table_string
graph = Graph(coordinates)
print(graph.create_coordinates_table())
Your code so far
# User Editable Region
import math
GRAVITATIONAL_ACCELERATION = 9.81
PROJECTILE = "∙"
x_axis_tick = "T"
y_axis_tick = "⊣"
class Projectile:
__slots__ = ("__speed", "__height", "__angle")
def __init__(self, speed, height, angle):
self.__speed = speed
self.__height = height
self.__angle = math.radians(angle)
@property
def speed(self):
return self.__speed
@speed.setter
def speed(self, new_speed):
self.__speed = new_speed
@property
def height(self):
return self.__height
@height.setter
def height(self, new_height):
self.__height = new_height
@property
def angle(self):
return round(math.degrees(self.__angle))
@angle.setter
def angle(self, new_angle_degrees):
self.__angle = math.radians(new_angle_degrees)
def __calculate_displacement(self):
v = self.__speed
h = self.__height
theta = self.__angle
g = GRAVITATIONAL_ACCELERATION
term_under_sqrt = (v**2 * (math.sin(theta))**2) + (2 * g * h)
sqrt_part = math.sqrt(term_under_sqrt)
numerator_part = (v * math.sin(theta)) + sqrt_part
displacement = (v * math.cos(theta) * numerator_part) / g
return displacement
def __calculate_y_coordinate(self, x):
y0 = self.__height
v0 = self.__speed
theta = self.__angle
g = GRAVITATIONAL_ACCELERATION
y = y0 + (x * math.tan(theta)) - ((g * x**2) / (2 * v0**2 * (math.cos(theta))**2))
return y
def calculate_all_coordinates(self):
coordinates_list = []
displacement = self.__calculate_displacement()
max_x = math.ceil(displacement)
for x in range(max_x):
y = self.__calculate_y_coordinate(x)
coordinates_list.append((x, y))
return coordinates_list
def __str__(self):
speed_val = self.speed
height_val = self.height
angle_degrees = self.angle
displacement_val = self.__calculate_displacement()
return (
f"\n"
f"Projectile details:\n"
f"speed: {speed_val} m/s\n"
f"height: {height_val} m\n"
f"angle: {angle_degrees}°\n"
f"displacement: {displacement_val:.1f} m\n"
)
def __repr__(self):
return f"Projectile({self.speed}, {self.height}, {self.angle})"
ball = Projectile(10, 3, 45)
coordinates = ball.calculate_all_coordinates()
print(ball)
class Graph:
__slots__ = ['__coordinates']
def __init__(self, coordinates):
self.__coordinates = coordinates
def __repr__(self):
return f"Graph({self.__coordinates!r})"
def create_coordinates_table(self):
table_string = "\n"
table_string += f" {'x':>3}{'y':>7}\n"
for x_coord, y_coord in self.__coordinates:
table_string += f" {x_coord:>3}{y_coord:>7.2f}\n"
return table_string
graph = Graph(coordinates)
print(graph.create_coordinates_table())
# User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Challenge Information:
Learn Encapsulation by Building a Projectile Trajectory Calculator - Step 14