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