Menu
Coddy logo textTech

Challenge #1

Lesson 10 of 14 in Coddy's Dictionary in Python course.

challenge icon

Challenge

Easy

Create a function named add_book that adds books to a library catalog represented as a dictionary. The function should take the title (the key), author, and publication year as input parameters and add a new book entry to the catalog with initial availability marked as "available."

Your function signature should look like this:

def add_book(catalog, title, author, year):
    # Your code here

  • catalog is the library catalog dictionary.
  • title is the title of the book.
  • author is the author of the book.
  • year is the publication year of the book.

Your function should add a new book entry to the catalog with the specified details, like this:

add_book(catalog, "The Great Gatsby", "F. Scott Fitzgerald", 1925)
add_book(catalog, "To Kill a Mockingbird", "Harper Lee", 1960)

After running the function with these examples, the catalog dictionary should include these two books with their details and an initial availability status.

Try it yourself

def add_book(catalog, title, author, year):
    # Your code here

All lessons in Dictionary in Python