Trying to solve library management in python core | Sololearn: Learn to code for FREE!

0

Trying to solve library management in python core

Know am missing something but can seem to remember books = { "Life of Pi": "Adventure Fiction", "The Three Musketeers": "Historical Adventure", "Watchmen": "Comics", "Bird Box": "Horror", "Harry Potter":"Fantasy Fiction", "Good Omens": "Comedy" } book = input() #your code goes here if book not in books: print("Not found")

4/8/2021 12:46:10 PM

Simisola Osinowo

7 Answers

New Answer

+1

i think since its a dictionary, you could compare input to the dictionary keys instead of the key:value pairs. if found, you'd need to access the dictionary by using the key and print out its genre value.

0

0

if book in books: print(books[book])

-1

A library management program has a dictionary of books with their corresponding genres. Take a book name as input and output the genre.

-1

This might help: print(books.get(input(), "Not found"))

-1

for i in books: if i==book: print(books[i]) break else: print("Not found")

-1

When the problem is asking to use the .get() method instead of if/else, I used: print(books.get(book, "Book not found"))