Error Message and Instructions for Ellens Alien Game (Issue 2992) (#3058)

Fenced the import of new_aliens_collection() function to throw custom error.
Changed instructions to clarify that new_aliens_collection() is meant to be *outside* the Alien() class.
Changed stub file to add a TODO around creating new_aliens_collection() explicitly outsied the Alien() class.
This commit is contained in:
BethanyG
2022-05-21 11:30:52 -07:00
committed by GitHub
parent 13be189550
commit dd4adabb51
3 changed files with 13 additions and 4 deletions

View File

@@ -108,16 +108,17 @@ For example:
2 2
``` ```
## 7. Object Creation ## 7. Creating a List of Aliens
Ellen loves what you've done so far, but she has one more favor to ask. Ellen loves what you've done so far, but she has one more favor to ask.
She would like a standalone function to create a `list` of alien objects, given a list of positions (as `tuples`). She would like a standalone (_outside the `Alien()` class_) function that creates a `list` of `Alien()` objects, given a list of positions (as `tuples`).
For example: For example:
```python ```python
>>> alien_start_positions = [(4, 7), (-1, 0)] >>> alien_start_positions = [(4, 7), (-1, 0)]
>>> aliens = new_aliens_collection(alien_start_positions) >>> aliens = new_aliens_collection(alien_start_positions)
...
>>> for alien in aliens: >>> for alien in aliens:
print(alien.x_coordinate, alien.y_coordinate) print(alien.x_coordinate, alien.y_coordinate)
(4, 7) (4, 7)

View File

@@ -20,3 +20,6 @@ class Alien:
""" """
pass pass
#TODO: create the new_aliens_collection() function below to call your Alien class with a list of coordinates.

View File

@@ -1,12 +1,17 @@
import unittest import unittest
import pytest import pytest
from classes import new_aliens_collection
try:
from classes import new_aliens_collection
except ImportError as err:
raise ImportError("We tried to import the new_aliens_collection() function, "
"but could not find it. Did you remember to create it?") from err
try: try:
from classes import Alien from classes import Alien
except ImportError as err: except ImportError as err:
raise ImportError("We tried to import the 'Alien' class, but could not find it. " raise ImportError("We tried to import the 'Alien' class from the classes.py file, but could not find it. "
"Did you remember to create it?") from err "Did you remember to create it?") from err