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

Sebastiaan van Vugt
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Sebastiaan van Vugt
Python Development Techdegree Graduate 13,554 Points

Should I provide the grade argument myself?

The grade argument has not been provided in this exercise and I'm unsure whether I should provide it. I have written the following in Idle but this isn't accepted:

class Student:
    name = "Sebastiaan"
    grade = 5

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

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

    def feedback(self):
        if self.grade > 50:
            studS.praise()
        elif self.grade < 50:
            studS.reassurance()


studS = Student()
studS.feedback()

Thank you for any help!

1 Answer

Cooper Runstein
Cooper Runstein
11,850 Points

Your function needs to be passed grade, feedback look closer to this:

def feedback(self, grade):
   #Do stuff
Sebastiaan van Vugt
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Sebastiaan van Vugt
Python Development Techdegree Graduate 13,554 Points

If I just change this, my answer is still not accepted. Also, I really don't understand how I can pass a "grade" argument that has not been defined. Should I define it somewhere?

Reply after updated feedback: I can somehow not reply to your latest update but that really helped. Thank you. I was unsure where and how to put in the grade info. One more thing though, I noticed I get the same result when leaving out "return" in front of self.praise() and self.reassurance(). Am I correct in thinking that these two returns are superfluous?

Cooper Runstein
Cooper Runstein
11,850 Points
class Student:
    name = "Sebastiaan"

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

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

    def feedback(self, grade):
        if grade > 50:
            return self.praise() #return the result of the function praise if the grade is over 50.
        return self.reassurance() #if the above statement hasn't returned something, return the result of reassurance.


studS = Student()
studS.feedback(70) #will return the result of praise called on the studS instance of the Student class.

From a non coding perspective, you define what a student is with the class Student, then you create an instance called "studS", who has all the qualities of a student. If this student is then given a low grade, you can run the method feedback on the student to see the feedback. Hopefully this makes some sense, let me know if I can clarify anything.