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 trialjhaideep Thodupunuri
4,316 Pointswhat's wrong in my code
Add a eq method for this book class. It should check if the author and title of the book are the same and return true if they are and false if they arenβt.
class Book:
def __init__(self, author, title):
self.author = author
self.title = title
def __str__(self):
return f'{self.author}, {self.title}'
def __eq__(self,other) :
if self.author == other.author and self.title == other.title :
return True
else :
return False
from book import Book
class BookCase:
def __init__(self):
self.books = []
def add_books(self, book):
self.books.append(book)
1 Answer
Brandon White
Full Stack JavaScript Techdegree Graduate 35,771 PointsHi jhaideep Thodupunuri,
The spaces before the colon in the eq method are the reasons for your error, in addition to the fact that there's no space after the comma between the parens.
Make it so that your code looks like the code below, and you should pass the challenge.
class Book:
def __init__(self, author, title):
self.author = author
self.title = title
def __str__(self):
return f'{self.author}, {self.title}'
def __eq__(self, other):
if self.author == other.author and self.title == other.title:
return True
else:
return False
Python is a language where indentation and whitespace are important.
Hope that helps.