just a general question, is your code meant to appear this messy? obviously when i put the right values in the code will look neater but im just interested if there is anyway i can write it better
Your code so far
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)
# User Editable Region
def __calculate_displacement(self):
d = math.cos() * (self.__speed*math.sin()*__self.angle+math.sqrt(self.__speed**2 * math.sin()+2*GRAVITATIONAL_ACCELERATION*self.__height/GRAVITATIONAL_ACCELERATION))
# User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36
Challenge Information:
Learn Encapsulation by Building a Projectile Trajectory Calculator - Step 4
I’ve blurred this solution. Please don’t post solutions into the forum. I’m just blurring this one instead of removing it since it’s relevant to this convo.
We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.
As long as you get the formula correct it should pass the test. I guess as a reward you get to see this tidy structure later.
To understand that v⋅cosθ is the horizontal component and v⋅sinθ is the vertical component and divide it up this way would take a pretty good understanding of this math.