Python Intensive Course Work


#1

Hi,

I am in the process of wrapping up the Pro Intensive Python Course, but I want to make sure that my code is correct before I run it through the Command Line and do any “final” steps. I’ve posted it below. I really appreciate the help; I want to make sure I’m doing it correctly.

Peace!

class User(object):
def init(self, name, email):
self.name = name
self.email = email
self.books = {}
pass

    def get_email(self):
        return user.email
        pass

    def change_email(self, address):
        new_email = self. email
        self.email.append("user.email")
        return(new_email)
    print("This user's email has been updated.")

def read_book (book, rating):
if self.books == 0, rating == book
return rating

def repr(self):
repr(self.name)
repr(self.email)
repr(self.books)
print (“name, email) + str(“Books Read: “) + str(self.books)
pass

def eq(self, other_user):
return (self.name if self.name == other.name) and (self.email == other.email)
pass

class Book(object):
def init(self, isbn, raitings):
self.title = title
self.isbn = isbn
self.raitings = {}
pass

def get_title(self):
return self.title
pass

def get_isbn(self):
return self.isbn
pass

def set_isbn(self, new_isbn):
self.isbn == new_isbn
print (“This book’s ISBN has been updated.”)

def add_rating (self, new_rating):
if rating >= 4:
self.rating == new_rating
else:
print(“Invalid Rating”)

def get_avg_rating (self, books):
for rating in self.books():
average = sum(rating)/len(rating)
return (average)
print (average)

def hash(self):
return hash((self.title, self.isbn))
else:
print (“TypeError: unhashable type:list”)

def eq(self, other_book):
return (self.name if self.title == other.title) and (self.isbn == other.isbn)
pass

class Fiction(object):
def init(self, title, author, isbn):
self.title = title
self.author = author
self.ratings = {}
pass

      def __init__(self, isbn):
	return (self.isbn)
    pass

def get_author:
return (author)

def repr(self):
repr(self.title)
repr(self.author)
repr(self.books)
print (title) + str(“by“) + str(self.author)
pass

class Non_Fiction(object):
def init(self, title, subject, level, isbn):
self.title = title
self.isbn = isbn
self.author = author
self.subject = subject
pass

def get_subject():
returns subject

def get_level():
returns level

def repr(self):
repr(self.title)
repr(self.subject)
repr(self.level)
repr(isbn)
print (title) + str(“a manual by“) + str(self.author)
pass

Non_Fiction.append(“Geology”, “Advanced”)

class TomeRater (self, users, books):
self.users = users
self.books = books
for books in books:
books += 1
return books

def create_book (self, title, isbn)
self.title = title
self.isbn = isbn
pass

def create_novel (self, title, author, isbn):
self.title = title
self.isbn = isbn
self.author = author
self.new_fiction = new_fiction
return new_fiction
pass

def create_non_fiction (title, subject, level, isbn):
self.title = title
self.isbn = isbn
self.level = level
self.new_non_fiction = new_non_fiction
return new_non_fiction

def add_book_to_user (self, book, email, rating):
self.book = book
self.email = email
self.users = users
self.rating = rating
for rating in rating:
if rating == 0:
print (“No user with email {email}!}

return (read_book (book, rating))
return (add_rating (book, rating))

def print_catalog (Book):
for book in books:
print (books)

def print_users (Users):
for user in Users
print (users)

def most_read_book (self, books):
for book in books:
self.books = books
print (self.books)

def highest_rated_book (self, Books):
for book in Books:
print (book.get_average_rating())

def most_positive_user (self, Users):
for user in Users:
print (user.get_average_rating())


#2

Given very few users on the forum have pro-intensive, i highly recommend you to use slack, you should have gotten a slack invite by email when you started pro-intensive. On slack you will very likely get feedback faster


#3

There are a tonne of questionable lines in this code. We see a lot of returns and pass that may not be needed, for one.

    def get_email(self):
        return user.email

    def change_email(self, address):
        new_email = self. email
        self.email.append("user.email")
        print("This user's email has been updated.")

The above is quite is bit removed from what we might expect.

    def get_email(self):
        return self.email

    def change_email(self, address):
        self.email = address
        print("This user's email has been updated.")

Instance representation is not correct as written…

def __repr__(self):
    repr(self.name)
    repr(self.email)
    repr(self.books)
    print (“name, email) + str(“Books Read: “) + str(self.books)
        pass

Only the print line is needed, and by rights it should be a return. The pass does not belong. Strings do not need to be cast as str() since they are str already.

def __repr__(self):
    return "Name: {}\nEmail: {}\nBooks Read:\n{}".format(self.name, self.email, self.books)

To use this method, print() the instance.

>>> instance = User("Wee Gillis", "wg@example.com")
>>> print (instance)
Name: Wee Gillis
Email: wg@example.com
Books Read:
{}
>>> instance.read_book("A Brief History of Time",10)
>>> print (instance)
Name: Wee Gillis
Email: wg@example.com
Books Read:
{'A Brief History of Time': 10}
>>> 

This is just a sampling of what needs to be repaired. We can keep helping if needs be, but we will need the instructions you have been following.


#4

Uhh, don’t you throw an error though?

I mean, instead of this:

print("No user with email {email}!")

Why not this?..:

throw("No user with email {email}!")

Oh wait nevermind, the Intensive Course would’ve wanted you to do that