#Python track: "MISSING FUNCTION" web test error in classes.py

11 messages · Page 1 of 1 (latest)

shrewd ravine
#

I'm working on https://exercism.org/tracks/python/exercises/ellens-alien-game using the in-browser editor. My code is:
'''
class Alien:

total_aliens_created = 0    

def __init__(self, x_coordinate, y_coordinate):
    Alien.total_aliens_created += 1
    self.health = 3
    self.x_coordinate = x_coordinate
    self.y_coordinate = y_coordinate

def new_aliens_collection(self, *args):
    pass

'''
But when I hit test I get this error:
'''
We received the following error when we ran your code:
ImportError while importing test module '.mnt.exercism-iteration.classes_test.py'.
Hint: make sure your test modules.packages have valid Python names.
Traceback:
.usr.local.lib.python3.11.importlib.init.py:126: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
.mnt.exercism-iteration.classes_test.py:16: in <module>
raise ImportError("\n\nMISSING FUNCTION --> We tried to import the "
E ImportError:
E
E MISSING FUNCTION --> We tried to import the new_aliens_collection() function from your classes.py file, but could not find it. Did you misname or forget to create it?
'''

I've tried replicating locally in vs code with Python 3, but it doesn't give me any errors - I can import alien from classes and run some obvious instance tests.

When I run "exercism test" locally I get the same error.

Is this just me?

Exercism

Can you solve Ellen's Alien Game in Python? Improve your Python skills with support from our world-class team of mentors.

warm dagger
#

It looks like you have the new_aliens_collection in the class, but it should be its own function which calls the class with a list of coordinates?

#

a function in a class is called a method, so I would imagine it would state its trying to call the new_aliens_method if it expected it to be in the class

errant owl
#

I don't understand the content of the code, but when using code blocks, instead of single quotes, you can use backquotes to do it well.

warm dagger
#

unindent the new_aliens_collection and retry

#
class Alien:

    totalalienscreated = 0

    def init(self, x_coordinate, y_coordinate):
        Alien.total_aliens_created += 1
        self.health = 3
        self.x_coordinate = x_coordinate
        self.y_coordinate = y_coordinate

def new_aliens_collection(self, *args):
    pass
#

you also will not have self, and *args but in the function it will call the alien class with the parameters you set for the function

shrewd ravine
#

D'oh! Thank you guys, that was of course the problem - having new_aliens_collection() as an instance method rather than a class method.

#

And thanks for the tip about the back-quotes - noted!

winged valve
#

Rather, a module function, not an instance method

#

It's not part of the class