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. 👁 291

Respond to this Question

First Name

Your Response

Similar Questions

  1. science

    a 5.o kg book is sitting on a table. which describes the forces acting on the book? a)there are no forces acting on the book b)the net force on the book is zero Since the weight of the book is cancelled out by the support of the

    asked by nancy on August 7, 2010
  2. 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
  3. MATH HELP

    Joseph borrowed a book from a library. The library charged a fixed rental for the book and a late fee for every day the book was overdue. The expression below shows the charges Joseph paid for the book when he returned it x days

    asked by Oscar on January 27, 2016
  4. maths

    on monday. Anna read 25% of her book.On Tuesday, she read 30%of her book.On Wednesday she read 25% her book.On Thursday she read 25% of her book.She still has 10% of her book left to read.How is this possible?

    asked by Oyama Mandindi on May 25, 2017
  1. physics

    A student places her 500 g physics book on a frictionless table. She pushes the book against a spring, compressing the spring by 4.0 cm, then releases the book. What is the book’s speed as it slides away? The spring constant is

    asked by anonymus on August 30, 2018
  2. physics

    The 1.1kg physics book in figure is connected by a string to a 250g coffee cup. The book is given a push up the slope and released with a speed of 2.5m/s . The coefficients of friction are μs =0.50 and μk =0.20. How far does the

    asked by Anonymous on February 25, 2015
  3. 11th grade Algebra 2

    At a college bookstore, Carla purchased a math textbook and a novel thjat cost a total of $54, not including tax. If the price if the math textbook, m, is $8 more than 3 times the price of the novel, n, write a system of linear

    asked by David Nipp on April 7, 2010
  4. AP Physics

    A Physics book has a height of 26 cm, a width of 22 cm, and a thickness of 4 cm. Find the pressure that the Physics book exerts on a desktop when the book lies face up and when the book is balanced on its spine. I know that P=F/A,

    asked by JL on November 15, 2009
  1. Writing Skills

    The call number of the book that you're looking for is R865.2. What do you know about the book based on this information? A. It's a book of or about Roman literature. B. It's a book about medicine. C. It's a reference book. D.

    asked by Mary on January 17, 2017
  2. Math

    A librarian is expanding some sections of the city library. He buys books at a special price from a dealer who charges one price for any hardback book and another price for any paperback book. For the children's section, Mr. Shah

    asked by crystal on March 12, 2018
  3. Physics

    A book with a mass of 1350 g is sitting on a desk. The ukf between the book and the desk is .45 and the ukf between the book and the desk is .30. a. how much horizontal force is required to start the book moving across the desk?

    asked by Anonymous on December 12, 2016
  4. Math

    A salesman sold a book at 5%of the marked price instead of discounting the marked price by 5%.If he sold the book for Rs.4.20,what was the price for which he should have sold the book?

    asked by ABC on May 14, 2017

You can view more similar questions or ask a new question.