samedi 25 octobre 2014

Python: Does this code imply a class and method "relationship?"


Vote count:

0




I'm working through exercises at Exercism.io and I don't understand one of the exercises. My task is to write a small module that will be imported at runtime.


The code below is part of the exercise, and neither Allergies or is_allergic_to are defined in the test file. It is up to me to define them in my module.


def test_has_the_right_allergies(self): allergies = Allergies(5) self.assertTrue(allergies.is_allergic_to('eggs'))




  1. I'm really not looking for a solution, as much as simple guidance on what a good programmer sees, and if it's true that I should approach the solution with a class and method, or just two functions with "method-capable" object (whatever THAT might be).




  2. As a hobbyist programmer, I'm having trouble understanding the syntax. I read is_allergic_to as a method, but I don't know what type of object is being returned by the call to Allergies() Essentially, does the code imply that I create a Class Allergies that has a method is_allergic_to?





asked 1 min ago







Python: Does this code imply a class and method "relationship?"

Aucun commentaire:

Enregistrer un commentaire