Need help to debug my function pls

Hi everyone ! Im trying to run this code but I get “name Tomerater is not defined” as an error. Could someone help me ?
thank you so much

#create Tomerater
class Tomerater:
def init(self):
self.users = {}
self.books = {}
def create_book (self, title, isbn):
new_book = Book(title , isbn)
return new_book
def create_novel (self, title, author, isbn):
new_Fiction = Fiction(title,author,isbn)
return new_Fiction
def create_non_fiction (self, title, subject, level, isbn):
new_Non_Fiction = Non_Fiction(title,author,isbn)
return new_Non_Fiction
def add_book_to_user(book, email, rating = None):
if self.user[email] not in self.user:
return print(“No user with email %s”) % (self.email)
else:
read_book(self, book, rating)
add_rating(self, book, rating)
if book in self.books:
self.books[book] += 1
else:
self.books.update(book, 1)
def add_user(name, email, user_books = None):
User_ = User(name, email)
return User
if user_books != None:
add_book_to_user(book, email, rating = None)

def print_catalog(self):
    for keys in self.books:
        print(keys)

def print_users(self):
    for values in self.users:
        print(values)

def most_read_book(self):
    max_value = ()
    for values in self.book:
        max_value.append(values)
    return max(max_value)

def highest_rated_book(self):
    for book in self.books:
        return book.get_average_rating(book)

def most_positive_user(self):
    for user in self.users:
        return user.get_average_rating(user)

Tome_Rater = Tomrater(“marion”, “Hp”)

Here is the linl :slight_smile:

The constructor for Tomrater does not accept a string.

class Tomerater:
  def init(self):
    self.users = {}
    self.books = {}

Tome_Rater = Tomrater(“marion”, “Hp”) wont work since this constructor does not exist.

Not sure how to fix your problem since i am not sure what you are trying to do with:
Tome_Rater = Tomrater(“marion”, “Hp”)

1 Like

17

Hello,
thank you for your time !
Here is the screenshot of the instructions.
When I opened the population file I had : Tome_rater=Tomerate()
So thought I had to insert a user and a book title in the parentheses but I appear to be mistaken…

Marion, you spelled Tomerater incorrectly in the instantiation, line 163:

Tome_Rater = Tomrater(“marion”, “Hp”)

Also, as pointed out by biirrra, the function is not initialized properly to take two arguments, and so, even if spelled correctly, will throw a Traceback:
TypeError: init() takes 1 positional argument but 3 were given

1 Like

I see now ! thank you very much. But the code stopped here now:
def create_non_fiction (self, title, subject, level, isbn):
new_Non_Fiction = Non_Fiction(title,author,isbn)
return new_Non_Fiction (line 122)

And I can’t understand why

1 Like
def create_novel (self, title, author, isbn):
        new_Fiction = Fiction(title,author,isbn)
        return new_Fiction

def create_non_fiction (self, title, subject, level, isbn):
        new_Non_Fiction = Non_Fiction(title, author, isbn)
        return new_Non_Fiction

The argument author that is used in the instantiation of the object new_Non_Fiction does not appear in the parameter list for the method, create_non_fiction() (as it does, for instance, for create_novel().)

Also, the argument list for the instantiation, new_Non_Fiction = Non_Fiction(title, author, isbn) must map to the parameter list for the class Non_Fiction, which it soes not.

1 Like

Thank you ! I have made the changes but I get that now : File “main.py”, line 101, in init
super(Non_Fiction,self).__init(title, isbn)
AttributeError: ‘super’ object has no attribute ‘_Non_Fiction__init’

Please post a link to the exercise when asking a question. It helps us immensely.

That’s the link of the file on github
Many thanks

We still need a link to the exercise, please.

Did you forget the “dunderscore” (__) on the right side of init?

… And, yes, please include that link to the exercise, in addition to the provided link to your code, so that others can follow.

Hi, I don’t undertand what you mean with the link to the exercice. I can give you the PDF that was provided to us :

TomeRater Instructions.pdf (100.0 KB)

Thank you for your help

1 Like

That’s fine, thanks.

Can you please post the code in the skeleton file TomeRater.py? We cannot access that page.

Also, populate.py so we can see what you see in that file. Thanks.