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 Your first method

I have doubt in Challenge Task

This class should look familiar!

First, I need you to add a method named praise to the Student class. It should take the self argument. Then, inside the praise method, return a positive message about the student using the name attribute.

As an example, it could say "You're doing a great job, Jacinta!" or "I really like your hair today, Michael!".

Feel free to change the name attribute to your own name, too!

first_class.py
class Student:
    name = "Your Name"

    def praise(self):
        print("You're doing a great job, Jacinta!",self.name)
obj=Student()
obj.praise()

I am getting the below error message

Oh no! You forgot the self argument in your praise method

Please let me know what is wrong in the above code

1 Answer

volhaka
volhaka
9,837 Points

There are several mistakes in your code.

  1. method should return message, not print message.

  2. Your message is not correct. You should use self.name as a part of message instead of Jacinta . There are several ways to do that:

f-string

f"You're doing a great job, {self.name}!"

or format

"You're doing a great job, {}!".format(self.name)