Learn Encapsulation by Building a Projectile Trajectory Calculator - Step 5

Tell us what’s happening:

not sure where i am going wrong. the output looks the same as the example

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)


    def __calculate_displacement(self):
        horizontal_component = self.__speed * math.cos(self.__angle)
        vertical_component = self.__speed * math.sin(self.__angle)
        squared_component = vertical_component**2
        gh_component = 2 * GRAVITATIONAL_ACCELERATION * self.__height
        sqrt_component = math.sqrt(squared_component + gh_component)
        
        return horizontal_component * (vertical_component + sqrt_component) / GRAVITATIONAL_ACCELERATION
        

# User Editable Region


    def __str__(self):
        displacement = self.__calculate_displacement()
        return f"Projectile Details:\nspeed: {self.__speed} m/s\nheight: {self.__height} m\nangle: {int(math.degrees(self.__angle))}°\ndisplacement: {displacement:.1f} m"
ball = Projectile(10, 3, 45)
print(ball)


# 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/125.0.0.0 Safari/537.36

Challenge Information:

Learn Encapsulation by Building a Projectile Trajectory Calculator - Step 5

Hi @jcant

Check the output again.
Make sure your code is fulfilling all the requirements.

Happy coding

I created a ball variable and called the projectile class.
i entered 10,3,45
i defined str
i formatted it with \n
i used math.degrees
i printed the function

i am not sure what else i am supposed to do as these were the directions

Did you read this part?

It should start and end with a new line character, the angle has to be written as an integer in degrees and the displacement should be printed with one decimal digit.

i don’t understand.. my output starts and ends with a new line, the degrees are shown as an integer and the displacement has one decimal digit..

Please post your updated code.

You need to start and end the f-string with a new line character.

this is my updated code:

return f"\nProjectile Details:\nspeed: {self.__speed} m/s\nheight: {self.__height} m\nangle: {int(math.degrees(self.__angle))}°\ndisplacement: {displacement:.1f} m\n"

now it is saying it is not passing. this is the hint, ’ The string representation for Projectile(45, 45, 45) should be correct.’ but when i change this it tells me it is wrong, too

The second word is lower cased.

I edited your post so that the code starts and ends on a new line.
This way the copy function is accessible.

Happy coding

thank you for the help

1 Like