# Python: Creating function

The value of the inventory of a particular book is the price of that book times the number of copies we have in stock. Write a function called inventory_value that takes a Book as its argument and returns the value of our inventory of that book. Then write a function called top_value that takes a list of Books as its argument and returns the Book object (from the list) that has the highest-vaue inventory. Finally, write a sequence of statements that prints a line in this form: The highest-value book is War and Peace by Tolstoy, Leo at a value of \$ 595.00.

So far, I've written this:

from collections import namedtuple
Book = namedtuple('Book', 'author title genre year price instock')
# Book attributes: author, title of book, category of book, year of publication, and number of copies available
BSI = [
Book('George Orwell', 'Animal Farm', 'Fiction', 1945, 9.99, 21),
Book('J.K. Rowling', 'Harry Potter and the Deathly Hallows', 'Fantasy', 2007, 24.26, 32),
Book('J.R.R. Tolkien', 'The Fellowship of the Ring', 'Fantasy', 1954, 10.87, 26),
Book('Toni Morrison', 'The Bluest Eye', 'Fiction', 1970, 11.02, 13),
Book('Ernesto Galarza', 'Barrio Boy', 'Autobiography', 1971, 13.50, 23),
Book('Stephen Chbosky', 'The Perks of Being a Wallflower', 'Fiction', 1999, 8.01, 25)]

def inventory_value(b: Book)->str:
return (b.price * b.instock)
assert(inventory_value(BSI[1])) == 776.32
assert(inventory_value(BSI[2])) == 282.62

def top_value(b: Book)->str:
for top_value in BSI:
if (b.price * b.instock) == max(inventory_value):
return(top_value.title)
print(top_value(BSI))

It's my function of top_value that isn't working out for me, but I can't tell what I'm doing wrong. I'm new to this and I'd like for someone to explain how I can go about doing this part of the problem. Thanks!

1. 👍 0
2. 👎 0
3. 👁 159

## Similar Questions

1. ### math

Book 1 255 book 2 235 book 3 178 book 4 299 book 5 150 book 6 67 book 7 82 book 8 267 book 9 188 book 10 142 book 11 281 book 12 138 book 13 326 book 14 264 book 15 103 ^ number of pages What would be the best graph or display to

asked by :I on April 30, 2017
2. ### to ms.sue

Lets say you had a book you bought at the book fair for \$4.99. at a book order diouloge, there was a 10 book set for \$27 with one of that book in it. what should you do with that book. I don't just want to give it away, I mean

asked by Celest on March 15, 2012
3. ### MATH PLEASE

Lansing Bookery regularly marks up books 40% of the selling price. The bookstore's cost on a new best-selling book is \$12.95 per book. What is the selling price of this book? 21.58 33.21 32.38 18.13

asked by BRAD on February 25, 2016
4. ### Physics

A student presses a book between his hands. The forces that he exerts on the front and back covers of the book are perpendicular to the book and are horizontal. The book weighs 31N. The coefficient of static friction between his

asked by Anonymous on June 11, 2012
5. ### physics,

A student presses a book between his hands The forces that he exerts on the front and back covers of the book are perpendicular to the book and are horizontal. The book weighs 30.8 N. The coefficient of static friction between his

asked by darren on November 28, 2011
6. ### Physics

A student presses a book between his hands, as the drawing indicates. The forces that he exerts on the front and back covers of the book are perpendicular to the book and are horizontal. The book weighs 32 N. The coefficient of

asked by kelly on February 15, 2010
7. ### physics

A student presses a book between his hands, as the drawing indicates. The forces that he exerts on the front and back covers of the book are perpendicular to the book and are horizontal. The book weighs 30.0 N. The coefficient of

asked by brian on January 27, 2011
8. ### C#

The Peterman Publishing Company has decided that no published book should cost more than 10 cents per page. Create a BookException class whose constructor requires three arguments: a string Book title, a double price and an int

asked by Isaih on August 29, 2012
9. ### Microeconomics - determining how many to sel

Hi, I would really appreciate it if someone could help me with these questions: An author earns royalties from his book that are specified as 10% of the book's selling price. The demand curve for this is straight and downward

asked by SuprNova on November 11, 2006
10. ### Math

marilyn plans to buy a book to read during her summer vacation. she has at most \$18 set aside to purchase the book. the sales tax in her state in 8%. If x is the maximum price if the book that she can buy to stay within her

asked by Iyana on August 26, 2016

More Similar Questions