Ellen's Alien Game introductions needs a fix

Found a little mistake in the Ellen’s Alien Game introduction example.
here:
Class attributes can be accessed from within instance methods in the same way that they are accessed outside of the class:

class MyClass:
    number = 5
    string = "Hello!"

    def __init__(self, location):
        self.location_x = location[0]
        self.location_y = location[1]

    # Alter instance variable location_x and location_y
    def change_location(self, amount):
        self.location_x += amount
        self.location_y += amount
        return  self.location_x, self.location_y

    # Alter class variable number for all instances from within an instance.
    def increment_number(self):
        # Increment the 'number' class variable by 1.
        MyClass.number += 1


>>> test_object_one = MyClass((0,0))
>>> test_object_one.number
5

>>> test_object_two = MyClass((13, -3))
>>> test_object_two.increment_number()
>>> test_object_one.number
6

“test_object_one.number” this should be: test_object_two.number, that’s the one being incremented and the one with 6 stored in it!

I’ll keep trying to help to make this great platform even better!
Julian

The whole point here is that the number is a class attribute and shared across all instances of the class. Updating number via test_object_two also effects test_object_one.

2 Likes

That’s the point - when defined like above, there is only one “number” among all instances of the MyClass. So the illustration is correct.

1 Like

ahhh I see, thank you. my mistake