Back to Freecodecamp

Step 3

curriculum/challenges/english/blocks/learn-encapsulation-by-building-a-projectile-trajectory-calculator/65fd4bd84561a14d3e720061.md

latest1.3 KB
Original Source

--description--

The class variable __slots__ has a special usage in Python classes. Declaring __slots__ and assigning it a sequence of strings restricts the creation of attributes to those included in that sequence. Also, it prevents the creation of the __dict__ special attribute and it allows for more efficient attribute access.

You should use the __slots__ variable inside the class to define which attributes the class has: assign to __slots__ a tuple containing 3 strings, each equal to one of the attribute names defined in the __init__.

--hints--

You should assign to __slots__ a tuple that contains '__height', '__speed', and '__angle'.

js
({test: () => assert(runPython(`
from itertools import permutations
slots = _Node(_code).find_class("Projectile").find_body().find_variable("__slots__")
perms = permutations(("__height", "__speed", "__angle"))
any(slots.is_equivalent(f'__slots__ = {perm}') for perm in perms)
`))})

--seed--

--seed-contents--

py
import math

GRAVITATIONAL_ACCELERATION = 9.81
PROJECTILE = "∙"
x_axis_tick = "T"
y_axis_tick = "⊣"

--fcc-editable-region--
class Projectile:

    def __init__(self, speed, height, angle):
        self.__speed = speed
        self.__height = height
        self.__angle = math.radians(angle)
--fcc-editable-region--