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

Bozhong Tao
Bozhong Tao
18,365 Points

Bummer! Exception: argument of type 'NoneType' is not iterable

Hi , could someone help with this one? if I delete the grade var in the beginning, it will prompt that "AttributeError, student object has no attribute 'grade'"

however, if I set a grade attribute, the input will always be the number I set in the first place rather than my input when I run the code in workspace. :(

some help will be appreciated, many thanks!

first_class.py
class Student:
    name = "bozhonge"
    grade = 0

    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 self.grade > 50:
            self.praise()
        if self.grade <= 50:
            self.reassurance()

2 Answers

Steven Parker
Steven Parker
230,995 Points

I assume you are referring to this part of the code:

    def feedback(self, grade):
        if self.grade > 50:
        # ...

Note that "self.grade" refers to the value stored in the class, but the parameter named "grade" is not being used.

To test the value given to the "feedback" method, use this instead:

        if grade > 50:

Or, if your intention was to change the stored value and then test it:

    def feedback(self, grade):
        self.grade = grade
        # ...

But either way, I suspect this is not related to your error message "argument of type 'NoneType' is not iterable". That message probably refers to a loop or membership operator, but I don't see either in this code.

Mark Nembhard
Mark Nembhard
1,387 Points

I got stuck on this just now. i thought the convention is to use the instance of the attribute or function in which case you always use the instance.attribute as in self.grade to refer to the attribute. I do understand you can use the class name and then the function with a name in the function parenthesis. Man i just need to get my head around this. Taking too much time

Bozhong Tao
Bozhong Tao
18,365 Points

Your explained it super clear and easy to understand. Both suggestions solved my problem, thank you Steven! :)