Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Object-Oriented Python Instant Objects Method Interactivity

Michael Cook
Michael Cook
5,864 Points

I don't think I understand Python Classes and 'self' very well, I'm stuck on another code challenge, can anyone help me?

Hi again, right now I'm learning Python classes and I'm probably not understanding some things. Mostly it's about 'self' and how that sorta thing works. Anyways I got to this coding challenge and this is what it asks me to do.

"Alright, I need you make a new method named 'feedback'. It should take an argument named 'grade'. Methods take arguments just like functions do. You'll still need 'self' in there, though. If 'grade' is above 50, return the result of the 'praise' method. If it's 50 or below, return the 'reassurance' method's result."

I went into my workspace with the code below and everything seems to work. When I run my program nothing pops up in the console unless I add a print function to the return statements of 'praise()' and 'reassurance()', if I do that and test out the 'feedback()' function, it seems to work perfectly fine. If I give the 'feedback' method an argument of 51 or above it will run the 'praise' method, if I give it an argument of 50 or below it will run the 'reassurance' method.

However the code challenge isn't passing me, it's giving me a "NameError" message of some sorts, I tried looking online and how to solve it, tried a few various methods, but nothing seemed to work.

This is the exact error it gave me. "Bummer: Exception: argument of type 'NoneType' is not iterable"

Could anyone help me and show me what I'm doing wrong and maybe give a little insight on how some of this technical Class and 'self' stuff works? Thanks!

first_class.py
class Student:
    name = "TestName"

    def praise(self):
        return "You inspire me, {}".format(self.name)

    def reassurance(self):
        return "Chin up, {}. You'll get it next time!".format(self.name)

    def feedback(self, grade):
        if grade > 50:
            self.praise()
        else:
            self.reassurance()
#end

5 Answers

Mark Sebeck
MOD
Mark Sebeck
Treehouse Moderator 37,799 Points

You want to return the value from self.praise() so try:

    return self.praise()
Steven Parker
Steven Parker
231,236 Points

Your use of "self" is correct. :+1:

But the challenge asks you to return the results of calling the methods, and you still need to add the "return" keyword in front of each of the calls:

            return self.praise()
        else:
            return self.reassurance()
Michael Cook
Michael Cook
5,864 Points

Where would I place 'return' on my code and what would it look like? What I did was simply add 'return' right below 'self.praise()' and 'self.reassurance()', it was indented too. It still gave me the same error anyways.

Steven Parker
Steven Parker
231,236 Points

Not below, but in front of the calls. I added an example to my answer.

Michael Cook
Michael Cook
5,864 Points

Oooooooooh, dang how did I not see that. Thank you both so much for your help!

Mark Sebeck
Mark Sebeck
Treehouse Moderator 37,799 Points

Keep at it Michael. Debugging will get easier the more you do it.

Michael Cook
Michael Cook
5,864 Points

Yeah, thank you guys for helping me so quickly, I gotta say this community is awesome!