+ 1

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")

8th Apr 2021, 12:46 PM
Simisola Osinowo
Simisola Osinowo - avatar
15 Answers
+ 1
it works like this : 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() if book in books: print(books[book]) #your code goes here else :
21st Sep 2021, 10:47 AM
hanane el otmani
hanane el otmani - avatar
+ 1
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 print (books.get(book, "Not found"))
2nd Dec 2021, 11:02 AM
Matt Webb
+ 1
This worked for me(: 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() #change this part to use the .get() method if book in books: print(books.get(book)) else: print("Not found")
22nd Feb 2022, 5:32 PM
Rich
Rich - avatar
0
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.
8th Apr 2021, 1:20 PM
Slick
Slick - avatar
0
Thanks
8th Apr 2021, 1:28 PM
Simisola Osinowo
Simisola Osinowo - avatar
0
if book in books: print(books[book])
5th Jul 2021, 2:17 PM
Rares-Vasile Irimus
Rares-Vasile Irimus - avatar
0
book = input() try: print(books[book]) except: print("Not found")
18th Oct 2021, 11:18 AM
Kholdarov Ilyosjon
Kholdarov Ilyosjon - avatar
0
#add the print statement in else part 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() if book in books: print(books[book]) else: print("Not found")
8th Jan 2022, 7:12 AM
Janvi Sharma
Janvi Sharma - avatar
0
# Most efficient simplest full answer 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() if book in books: print(books[book]) else: print("Not found")
27th Feb 2022, 12:38 AM
Jake Ambrose
Jake Ambrose - avatar
0
class Book: def __init__(self, title, author): self.title = title self.author = author class Ebook(Book): def __init__(self, title, author, file_size): super().__init__(title, author) # Call the parent class constructor self.file_size = file_size # Initialize the file_size attribute # Creating an instance of Ebook my_ebook = Ebook("1984", "George Orwell", 10) print(my_ebook.title) # Output: 1984 print(my_ebook.author) # Output: George Orwell print(my_ebook.file_size, 'MB') # Output: 10 MB
27th Sep 2024, 12:36 PM
Abdoulrazak Omar Bogoreh
Abdoulrazak Omar Bogoreh - avatar
- 1
A library management program has a dictionary of books with their corresponding genres. Take a book name as input and output the genre.
8th Apr 2021, 12:47 PM
Simisola Osinowo
Simisola Osinowo - avatar
- 1
This might help: print(books.get(input(), "Not found"))
8th Apr 2021, 2:10 PM
Calvin Thomas
Calvin Thomas - avatar
- 1
for i in books: if i==book: print(books[i]) break else: print("Not found")
29th Jun 2021, 1:30 PM
Akhil Guptha
- 1
When the problem is asking to use the .get() method instead of if/else, I used: print(books.get(book, "Book not found"))
24th Aug 2021, 5:55 PM
Sorin Sfechis
Sorin Sfechis - avatar
- 1
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() print(books.get(book, "Not found"))
5th Nov 2021, 8:01 AM
Laura J.
Laura J. - avatar