diff --git a/concepts/classes/about.md b/concepts/classes/about.md index 11b03643543..9b6a8a0dfb7 100644 --- a/concepts/classes/about.md +++ b/concepts/classes/about.md @@ -185,10 +185,10 @@ class Demo: The moment that `.add_two()` is called, and `self.new_var += 2` is read, `new_var` changes from a class variable to an instance variable of the same name. This can be useful during initialization when all instances of a class will need some attribute(s) to start with the same value. -However, the instance variable then shadows* the class variable, making the class variable inaccessible from the instance where it is shadowed. +However, the instance variable then [_shadows_](https://oznetnerd.com/2017/07/17/python-shadowing/) the class variable, making the class variable inaccessible from the instance where it is shadowed. Given this situation, it may be safer and clearer to set instance attributes from the `__init__()` method as `self.`. ~~~~ -_*[_shadows_][shadowing] + ## Methods @@ -240,7 +240,7 @@ class MyClass: def change_location(self, amount): self.location_x += amount self.location_y += amount - return self.location_x, self.location_y + return self.location_x, self.location_y # Make a new test_object with location (3,7) >>> test_object = MyClass((3,7)) @@ -267,7 +267,7 @@ class MyClass: def change_location(self, amount): self.location_x += amount self.location_y += amount - return self.location_x, self.location_y + return self.location_x, self.location_y # Alter class variable number for all instances from within an instance. def increment_number(self): @@ -322,4 +322,3 @@ class MyClass: [dunder]: https://mathspp.com/blog/pydonts/dunder-methods [oop]: https://www.educative.io/blog/object-oriented-programming [dot notation]: https://stackoverflow.com/questions/45179186/understanding-the-dot-notation-in-python -[shadowing]: https://oznetnerd.com/2017/07/17/python-shadowing/ diff --git a/exercises/concept/ellens-alien-game/.docs/hints.md b/exercises/concept/ellens-alien-game/.docs/hints.md index e3045b60169..54df99eee44 100644 --- a/exercises/concept/ellens-alien-game/.docs/hints.md +++ b/exercises/concept/ellens-alien-game/.docs/hints.md @@ -20,7 +20,7 @@ ## 4. The `teleport` Method - Remember that `object methods` are always passed `self` as the first parameter. -- Instance attributes can be updated from a method by using `self.` = ``. +- Instance attributes can be updated from a method by using `self. = `. ## 5. The `collision_detection` Method @@ -39,4 +39,4 @@ - A `tuple` would be a _single_ parameter. - The Alien constructor takes _2 parameters_. - Unpacking what is _inside_ the tuple would yield two parameters. -- The standalone function is outside of the `class` +- The standalone function is outside of the `class`. diff --git a/exercises/concept/ellens-alien-game/.docs/instructions.md b/exercises/concept/ellens-alien-game/.docs/instructions.md index 81ec62dbe5a..1093895f251 100644 --- a/exercises/concept/ellens-alien-game/.docs/instructions.md +++ b/exercises/concept/ellens-alien-game/.docs/instructions.md @@ -31,9 +31,9 @@ It is up to you if `hit()` takes healths points _to_ or _below_ zero. ```python >>> alien = Alien(0, 0) ->>> alien.health # Initialized health value. +>>> alien.health 3 # Decrements health by 1 point. @@ -103,8 +103,8 @@ For example: 2 >>> alien_one.total_aliens_created 2 ->>> Alien.total_aliens_created # Accessing the variable from the class directly +>>> Alien.total_aliens_created 2 ``` @@ -120,7 +120,7 @@ For example: >>> aliens = new_aliens_collection(alien_start_positions) ... >>> for alien in aliens: - print(alien.x_coordinate, alien.y_coordinate) +... print(alien.x_coordinate, alien.y_coordinate) (4, 7) (-1, 0) ``` diff --git a/exercises/concept/ellens-alien-game/.docs/introduction.md b/exercises/concept/ellens-alien-game/.docs/introduction.md index ea1fc940fa4..fead4bf6401 100644 --- a/exercises/concept/ellens-alien-game/.docs/introduction.md +++ b/exercises/concept/ellens-alien-game/.docs/introduction.md @@ -182,7 +182,7 @@ class MyClass: def change_location(self, amount): self.location_x += amount self.location_y += amount - return self.location_x, self.location_y + return self.location_x, self.location_y # Make a new test_object with location (3,7) >>> test_object = MyClass((3,7)) @@ -209,7 +209,7 @@ class MyClass: def change_location(self, amount): self.location_x += amount self.location_y += amount - return self.location_x, self.location_y + return self.location_x, self.location_y # Alter class variable number for all instances from within an instance. def increment_number(self): diff --git a/exercises/concept/ellens-alien-game/.meta/exemplar.py b/exercises/concept/ellens-alien-game/.meta/exemplar.py index d4441f3b749..1aeae691340 100644 --- a/exercises/concept/ellens-alien-game/.meta/exemplar.py +++ b/exercises/concept/ellens-alien-game/.meta/exemplar.py @@ -6,9 +6,9 @@ class Alien: Attributes: (class) total_aliens_created (int): Total number of Alien instances. - x_coordinate (int): Position on the x-axis. + x_coordinate (int): Position on the x-axis. y_coordinate (int): Position on the y-axis. - health (int): Number of health points. + health (int): Number of health points. Methods: hit(): Decrement Alien health by one point. @@ -29,9 +29,9 @@ def __init__(self, x_coordinate, y_coordinate): health (int): Number of health points. Attributes: - x_coordinate (int): Position on the x-axis. + x_coordinate (int): Position on the x-axis. y_coordinate (int): Position on the y-axis. - health (int): Number of health points. Defaults to 3. + health (int): Number of health points. Defaults to 3. Returns: Alien (Alien Object): New Alien. @@ -59,7 +59,7 @@ def is_alive(self): """Return if the Alien is alive. Returns: - bool: Is the Alien Alive? + bool: Is the Alien Alive? """ return self.health > 0 @@ -94,11 +94,11 @@ def collision_detection(self, other): def new_aliens_collection(positions): """Create a list of Alien instances from a list of coordinate tuples. - Parameters: - positions (list[tuple]): List of (x, y) coordinates in tuples.. + Parameters: + positions (list[tuple]): List of (x, y) coordinates in tuples. - Returns: - list[object]: List of Alien objects. + Returns: + list[object]: List of Alien objects. """ return [Alien(position[0], position[1]) for position in positions] diff --git a/exercises/concept/ellens-alien-game/classes.py b/exercises/concept/ellens-alien-game/classes.py index f3fbe843832..f64d1055e34 100644 --- a/exercises/concept/ellens-alien-game/classes.py +++ b/exercises/concept/ellens-alien-game/classes.py @@ -6,9 +6,9 @@ class Alien: Attributes: (class) total_aliens_created (int): Total number of Alien instances. - x_coordinate (int): Position on the x-axis. + x_coordinate (int): Position on the x-axis. y_coordinate (int): Position on the y-axis. - health (int): Number of health points. + health (int): Number of health points. Methods: hit(): Decrement Alien health by one point. @@ -21,5 +21,5 @@ class Alien: pass -#TODO (Student): Create the new_aliens_collection() function below to call your Alien class with a list of coordinates +#TODO (Student): Create the new_aliens_collection() function below to call your Alien class with a list of coordinates