* Python Programming *
Write a class definition named Book. The Book class should have instance variables for a book's title, the author's name, and the publisher's name. The class should also have the following:
a) An __init__ method for the class. The method should accept an argument for each of the instance variables.
b) An __str__ method that returns a string indicating the state of the object.
Use the Car class file in resources/Margie's Notes/car.py as an example, but make the instance variables public by not using underbars.
Add this code to the bottom of the file, and run the program.
''' Unit Test '''
if __name__ == "__main__":
book = Book("The Cat in the Hat", "Dr. Seuss", "Random
House")
print(book)
class Book: def __init__(self, title, author, publisher): self.title = title self.author = author self.publisher = publisher def __str__(self): return "Title: {}, Author: {}, Publisher: {}".format(self.title, self.author, self.publisher) if __name__ == "__main__": book = Book("The Cat in the Hat", "Dr. Seuss", "Random House") print(book)
Get Answers For Free
Most questions answered within 1 hours.