Question

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 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###################################

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,...
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, 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...

  • 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.

  • 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...

  • 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...

  • 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...

  • 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...

  • Create the Employee class: The Employee class has three attributes: private: string firstName; string lastName; string...

    Create the Employee class: The Employee class has three attributes: private: string firstName; string lastName; string SSN; The Employee class has ▪ a no-arg constructor (a no-arg contructor is a contructor with an empty parameter list): In this no-arg constructor, use “unknown” to initialize all private attributes. ▪ a constructor with parameters for each of the attributes ▪ getter and setter methods for each of the private attributes ▪ a method getFullName() that returns the last name, followed by a...

  • The first part is “addBook method” the Second part is “checkOut method” the third part is...

    The first part is “addBook method” the Second part is “checkOut method” the third part is “isAvailable method” and the fourth is “__str__ method”. What you have to do is complete the sample code provided below. do not change the sample code and print result. The program's goal is to keep track of books in a library. Books are stored in dictionaries, with the book title as the key. Source Code is: class Library: bookCount = 0 def __init__(self): self.cardCatalog...

  • Create the Python code for a program adhering to the following specifications. Write an Employee class...

    Create the Python code for a program adhering to the following specifications. Write an Employee class that keeps data attributes for the following pieces of information: - Employee Name (a string) - Employee Number (a string) Make sure to create all the accessor, mutator, and __str__ methods for the object. Next, write a class named ProductionWorker that is a subclass of the Employee class. The ProductionWorker class should keep data attributes for the following information: - Shift number (an integer,...

  • 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.

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