Learn Encapsulation by Building a Projectile Trajectory Calculator - Step 4

Tell us what’s happening:

Did I get the formula wrong or something? It keeps saying that it does not return the correct value.

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):
        v = self.__speed
        a = self.__angle
        g = GRAVITATION_ACCELERATION
        h = self.__height
        return (v * math.cos(a) * (v * math.sin(a) * math.sqrt(v**2 * math.sin(a)**2 + 2 * g * h))) / g

# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.6 Safari/605.1.15

Challenge Information:

Learn Encapsulation by Building a Projectile Trajectory Calculator - Step 4

double check this 

Oh yeah I see it now thx. But it is still not working.


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)
        
    def __calculate_displacement(self):
        v = self.__speed
        a = self.__angle
        g = GRAVITATIONAL_ACCELERATION
        h = self.__height
        return (v * math.cos(a) * (v * math.sin(a) * math.sqrt(v**2 * math.sin(a)**2 + 2 * g * h))) / g

double check the formula, you have something wrong

I suggest breaking this down into two variables and doing it so lesser chances of making a mistake. But the issue is that you are using * instead of a +

code removed by moderator

hi @archana115

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge. How to Help Someone with Their Code Using the Socratic Method

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.