OneCompiler

addCharityBooks

154
library = {"magazines": list()}
# adding a new key and value pair
library["books"] = {
    "ISBN1": {
        "title": "A is for Alibi",
        "year": 1882,
        "genre": "Detective",
        "author": "Agatha Christie"
    },
    "ISBN2": {
            "title": "B is for Burglar",
            "year": 1885,
            "genre": "Fiction",
            "author": "Thomas Christie"
        }
}
print(library)

library["books"]["ISBN3"] = {
        "title": "C is for Comment",
        "year": 1885,
        "genre": "Fiction",
        "author": "Thomas Christie"
}
print(f'The book with ID: ISBN3 added: {library["books"]["ISBN3"]}')

library["books"]["ISBN3"] = {
        "title": "A is for Alibi",
        "year": 1882,
        "genre": "Detective",
        "author": "Agatha Christie"
}
print(f'The book with ID: ISBN3 updated: {library["books"]["ISBN3"]}')
library["magazines"] = {"title": "BBC Uzbek"}
print("library: ", library)
initial_number_books = len(library["books"])
hasBooks = input("Are there books to start? (Yes/No)")
total_count = 0
unique_books = 0
count_existed = 0
# YES YEs Yes yES yeS yes ...
while hasBooks.lower() == 'yes':
    book_id = input("Enter the ID of the book: ")
    # if the book is already in the library of books
    # skip the operation: don't write the details, send to library
    if not (book_id in library["books"]):
        book_title = input("Enter the title of the book: ")
        book_author = input("Enter the author of the book: ")
        book_year = input("Enter the publication year of the book: ")
        book_genre = input("Enter the genre of the book: ")
        library["books"][book_id] = {
            "title": book_title,
            "author": book_author,
            "year": book_year,
            "genre": book_genre
        }
        unique_books += 1
    total_count += 1
    hasBooks = input("Are there books to start? (Yes/No)")
count_existed = total_count - unique_books