Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

def expensiveBooks (price, listOfBooks): ''' - Returns a list of book titles of Books that are greater or equal to the value price. - If

def expensiveBooks(price, listOfBooks): ''' - Returns a list of book titles of Books that are greater or equal to the value price. - If price is not a number type, then return an empty list ([]). - If listOfBooks is not a list type, then return an empty list ([]). - Elements in listOfBooks may contain multiple types (not necessarily Books). You can check if an element is a Book object with type(value) == Book. You can "skip" an element that's not a Book and continue checking other elements in listOfBooks. - You can assume Book objects are constructed correctly (i.e. title and author are strings, and book prices are either an int or float). - Note: You must obtain values of a book object using the name of the object's attributes (.title, .author, .price) instead of indexing them for full credit (as discussed in lecture). - Hint: Think of appending book titles to a list (recall .append) when the cost of the book is greater than the value price, and returning the list of accumulated book titles. ''' return "stub"

from lab03 import expensiveBooks, Book b1 = Book("Title1", "Author1", 5.99) b2 = Book("Title2", "Author2", 0.99) b3 = Book("Title3", "Author3", 20) b4 = Book("Title4", "Author4", 0) b5 = Book("Title5", "Author5", 100) bookList = [b1,b2,b3,b4,b5] # Tests for expensiveBooks def test_expensiveBooks_1(): assert expensiveBooks("0", bookList) == [] def test_expensiveBooks_2(): assert expensiveBooks(5.99, bookList) == ['Title1','Title3','Title5'] def test_expensiveBooks_3(): assert expensiveBooks(25, bookList) == ['Title5'] def test_expensiveBooks_4(): assert expensiveBooks(5.99, (b1,b2)) == [] def test_expensiveBooks_5(): assert expensiveBooks(101, bookList) == [] 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Semantics In Databases Second International Workshop Dagstuhl Castle Germany January 2001 Revised Papers Lncs 2582

Authors: Leopoldo Bertossi ,Gyula O.H. Katona ,Klaus-Dieter Schewe ,Bernhard Thalheim

2003rd Edition

3540009574, 978-3540009573

More Books

Students also viewed these Databases questions

Question

LO 14-2 How to create a strategy for successful interviewing.

Answered: 1 week ago