Question: PART 1 : Working with dict Write code to do the following: 1 a . Copy the following class into lab 5 sol.py ` `
PART : Working with dict
Write code to do the following:
a Copy the following class into labsol.py
class Book:
def initself title, pubyr price:
self.title title # title of book
self.pubyr pubyr # publication year
self.price price # price of book
def getTitleself:
return self.title
def getPubyrself:
return self.pubyr
def setPubyrself year:
self.pubyr year
b Create different instances objects bookl, book and book of class Book with suitable values for the parameters and put them in a list called booklist
c Write the str method for Book class. This should output the title of the book and the year it was published. For example, The Hobbit published in
d
Write method called getPriceself price for Book class. This method returns the price of the book.
Write method called setPriceself price for Book class. This method sets the price of the book.
e For each book in booklist, print the information for the book using the str method
Sample output :
C:Program Files xPythonpythd
OUTPUT FOR PART
The Hobbit published in
A Good Story published in
Python Programming published in
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
