Question

Create a Python file (book.py) that has a class named Book. Book class has four attributes, title...

Create a Python file (book.py) that has a class named Book.

Book class has four attributes, title (string), author(string), isbn(string), and year(int).

  • Title - the name of the book.
  • Author - the name of the persons who wrote the book.
  • ISBN - is a unique 13 digit commercial book identifier.
  • Year - the year the title was printed.

Your class should have the following methods:

(1) __init__(self, title, author, isbn, year): This method called when an object (book) is created from the class Book and it allows the class to initialize the attributes of a class.

(2) The Getter methods: Four different methods. Each method should return the value of an atrribute. The four methods are:

  • get_title(self)
  • get_author(self)
  • get_isbn(self)
  • get_year(self)

(3) The Setter methods: Four different methods. Each method should assign a new value to the attribute. The four methods are:

  • set_title(self, value)
  • set_author(self, value)
  • set_isbn(self, value)
  • set_year(self, value)

(4) __str__(self): This methid should return a string that has the book information. The string should look like the following:

Book Title    : Love Python
The Auther    : CUN students
Book ISBN     : 1234567890
Year Published: 2019
0 0
Add a comment Improve this question Transcribed image text
Answer #1

# -*- coding: utf-8 -*-
"""
Created on Tue Apr 16 12:09:34 2019

@author: KP
"""

#Class declaration starts here

class Book:
title = ''
author = ''
isbn = 0
year = 0
  
def __init__(self,title, author, isbn, year):
self.title = title
self.author = author
self.isbn = isbn
self.year = year
  
def get_title(self):
return self.title
  
def get_author(self):
return self.author
  
def get_isbn(self):
return self.isbn
  
def get_year(self):
return self.year
  
def set_title(self,value):
self.title = value
  
def set_author(self,value):
self.author = value
  
def set_isbn(self,value):
self.isbn = value
  
def set_year(self,value):
self.year = value
  
#__str__ function help us in returning any message directly in return statement
def __str__(self):
return "Book Title:"+"\t"+self.title+"\n"+\
"The Author:"+"\t"+self.author+"\n"+\
"Book ISBN:"+"\t"+str(self.isbn)+"\n"+\
"Year Published:"+"\t"+str(self.year)

#\ symbol is used to join current line to the next line

#Class declaration ends here

############Below is object declaration and functions calling###########
NewBook = Book('Start with What','Simon S.',1234567,2016)#Declaration of object NewBook

print("Printing the initial values of New Book function:")
print(NewBook)#__str__ function will be called

NewBook.set_title('Start with WHY')#set title using set_title function


NewBook.set_author('Simon sinek')#Set author name using set_authoer function


NewBook.set_isbn(987654)#Set isbn using set_isbn function


NewBook.set_year(2015)#Set year using set_year function


print("\n")#New line
print("Printing the new values of New Book function:")

print(NewBook)#Print the new values of NewBook object

####################################Output Image###################################

Printing the initial values of New Book function: Book Title: The Author: Book ISBN: Year Published: 2016 Start with What Sim

Add a comment
Know the answer?
Add Answer to:
Create a Python file (book.py) that has a class named Book. Book class has four attributes, title...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a Python file (book.py) that has a class named Book. Book class has four attributes,...

    Create a Python file (book.py) that has a class named Book. Book class has four attributes, title (string), author(string), isbn(string), and year(int). Title - the name of the book. Author - the name of the persons who wrote the book. ISBN - is a unique 13 digit commercial book identifier. Year - the year the title was printed. Your class should have the following methods: (1) __init__(self, title, author, isbn, year): This method called when an object (book) is created...

  • Write a definition for a class named Book with attributes title, price and author, where author...

    Write a definition for a class named Book with attributes title, price and author, where author is a Contact object and title is a String, and price is a float number. You also need to define the Contact class, which has attributes name and email, where name and email are both String. Instantiate a couple of Book objects that represents books with title, price and author (You can come up with the attributes values for each object) Write a function...

  • Using Python. Complete the following: Create a class called Pet that has two attributes: name and...

    Using Python. Complete the following: Create a class called Pet that has two attributes: name and breed Provide a constructor that accepts the data to initialize these attributes Provide the appropriate getter and setter methods Create a Pet object called dog and set its name to "Otis" and breed to "Pug". Print the dog's name and breed to the console.

  • reate a class called Person with the following attributes: name - A string representing the person's...

    reate a class called Person with the following attributes: name - A string representing the person's name age - An int representing the person's age in years As well as appropriate __init__ and __str__ methods, include the following methods: get_name(self) - returns the name of the person get_age(self) - returns the age of the person set_name(self, new_name) - sets the name for the person set_age(self, new_age) - sets the age for the person is_older_than(self, other) - returns True if this...

  • Need help with python assignment Create a class called Book that stores a book's title, author,...

    Need help with python assignment Create a class called Book that stores a book's title, author, and price. Name them using those words. You should be able to create a new book with the line: new book Book Zen of Python "Tim Peters", 12.95) Answer.

  • FOR JAVA: Summary: Create a program that stores info on textbooks. The solution should be named...

    FOR JAVA: Summary: Create a program that stores info on textbooks. The solution should be named TextBookSort.java. Include these steps: Create a class titled TextBook that contains fields for the author, title, page count, ISBN, and price. This TextBook class will also provide setter and getter methods for all fields. Save this class in a file titled TextBook.java. Create a class titled TextBookSort with an array that holds 5 instances of the TextBook class, filled without prompting the user for...

  • Write an entire class called Movie that stores an instance variable named title for the title...

    Write an entire class called Movie that stores an instance variable named title for the title of the movie as a string. Write the corresponding getter and setter methods (getTitle, setTitle), and a constructor that takes one parameter (string for the title). Include both the class definition and method definitions! Be sure to use appropriate visibility modifiers. Assume all includes and using namespace std are already in the file. Do not try to make header files.

  • You need to program a simple book library system. There are three java classes Book.java   //...

    You need to program a simple book library system. There are three java classes Book.java   // book object class Library.java   //library class A2.java //for testing The Book.java class represents book objects which contain the following fields title: a string which represents the book title. author: a string to hold the book author name year: book publication year isbn: a string of 10 numeric numbers. The book class will have also 3 constructors. -The default no argument constructor - A constructor...

  • Write a class named Book containing: Two instance variables named title and author of type String....

    Write a class named Book containing: Two instance variables named title and author of type String. A constructor that accepts two String parameters. The value of the first is used to initialize the value of title and the value of the second is used to initialize author. A method named toString that accepts no parameters. toString returns a String consisting of the value of title, followed by a newline character, followed by the value of author.

  • C# programming 50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (Strin...

    C# programming 50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (String) edition ( int) published year (int) Constructor that takes all of the above variables as input parameters. set/get methods ToString method// that return sting representation of Book object. 2-Create the sub class New_Book that is derived from the base class Book and has the following instance variables, constructor, and methods: title...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT