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

Charly Kusch
Charly Kusch
1,815 Points

Can't find the reason for the Error: "Bummer: Exception: argument of type 'NoneType' is not iterable" in my code

I'm missing something on this task, as I somehow thought I could just add the grade as an argument after self and let it run like this (see attached code). I always get the NoneType Error, even if I add grade to my class or store grade in self.grade first.

It would be nice if someone could point me in the right direction, as I saw a similar question on here that didn't quite help me get to a solution.

Thanks!

first_class.py
class Student:
    name = "Charly"

    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()

1 Answer

Hi

Take a look at the sequence of the calls and you will clearly see why you are getting this error. Here is a setup to walk through what happens:

class Student:
    name = "Charly"

    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()

### Main Body Of This Example ####
student = Student()
a_str = student.feedback(100)
print(a_str)
1 - you make a call to feedback in this line:
a_str = student.feedback(100)

2- then feedback calls praise in this line:
self.praise()

3- Now praise returns a string 'You inspire me, Charly' to feedback 

4- BUT feedback returns nothing to Main Body.  There is no return statement in method feedback?

This is why downstream you will get an error as you described in your question.

Hope this helps

Charly Kusch
Charly Kusch
1,815 Points

Thanks a lot! That helped me understand my stupid mistake.

Great feedback, thanks for posting this thoughtful answer.