Question: I need help writing a function build_instances that will read the data from the file, create instances of FictionBook and NonFictionBook from the data, assign

I need help writing a functionbuild_instancesthat will read the data from the file, create instances of FictionBook and NonFictionBook from the data, assign these instances to a Book list and return the Book list.

and also write functionbuild_invoicethat accepts the Book list and a quantity list and returns the grand total of all books sold and the number of FictionBooks sold.

and finaly write themainfunction that defines the quantity list as [12, 8, 3, 53, 7, 23, 14, 5], prints the book list and then callsbuild_instancesandbuild_invoiceand then prints as follows.

Title Abraham Lincoln Vampire Hunter Author Grahame-Smith Publisher Wiley Price 13.99

Title Frankenstein Author Shelley Publisher Prescott Price 7.99

Title Life of Kennedy Author Jones Publisher Pearson Price 12.9 Fiction Type biography

Title Dracula Author Stoker Publisher Addison Price 5.99

Title Curse of the Wolfman Author Hageman Publisher Wesley Price 10.59

Title How to Pass Java Author Willis Publisher Wiley Price 1.99 Fiction Type technology

Title The Mummy Author Rice Publisher Addision Price 7.99

Title History of Texas Author Smith Publisher Prescott Price 9.75 Fiction Type history

The grand total is $868.48

The total fiction books sold is 94

(please include some explanation for me so I can compare your method to what I have already done)

Thank you

This is what I have done so far

f = open("books.txt", "w")

data = ['Fiction;Abraham Lincoln Vampire Hunter;Grahame-Smith;Wiley;13.99',

'Fiction;Frankenstein;Shelley;Prescott;7.99',

'NonFiction;Life of Kennedy;Jones;Pearson;12.90;biography',

'Fiction;Dracula;Stoker;Addison;5.99',

'Fiction;Curse of the Wolfman;Hageman;Wesley;10.59',

'NonFiction;How to Pass Java;Willis;Wiley;1.99;technology',

'Fiction;The Mummy;Rice;Addision;7.99',

'NonFiction;History of Texas;Smith;Prescott;9.75;history']

f = open ('books.txt','w')

for book in data:

f.write(book + ' ')

f.close()

class Book:

def __init__(self, title, author, publisher, price):

self.title = title

self.author = author

self.publisher = publisher

self.price = price

def calculate_charge (self,quantity):

return quantity*self.price

class FictionBook(Book):

def __init__(self):

pass

class NonFictionBook(Book):

def __init__(self,category):

self.category = category

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!