0
0
Pythonprogramming~15 mins

Accessing values using keys in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Accessing values using keys
๐Ÿ“– Scenario: You are managing a small library system. You have a dictionary that stores book titles as keys and their authors as values.
๐ŸŽฏ Goal: You will create a dictionary of books and authors, then access the author of a specific book using its title as the key.
๐Ÿ“‹ What You'll Learn
Create a dictionary called library with exact book titles and authors
Create a variable called book_title with the exact book title to look up
Access the author of the book using the book_title key from the library dictionary
Print the author name
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Dictionaries are used to store and look up data quickly, like finding a book's author by its title in a library system.
๐Ÿ’ผ Career
Understanding how to access values using keys is essential for data handling in many programming jobs, including web development, data analysis, and software engineering.
Progress0 / 4 steps
1
Create the library dictionary
Create a dictionary called library with these exact entries: 'The Hobbit': 'J.R.R. Tolkien', '1984': 'George Orwell', 'Pride and Prejudice': 'Jane Austen'
Python
Need a hint?

Use curly braces {} to create a dictionary with keys and values separated by colons.

2
Set the book title to look up
Create a variable called book_title and set it to the string '1984'
Python
Need a hint?

Use an equals sign = to assign the string '1984' to the variable book_title.

3
Access the author using the book title key
Create a variable called author and set it to the value from the library dictionary using the key stored in book_title
Python
Need a hint?

Use square brackets [] with the dictionary name and the key variable inside to get the value.

4
Print the author
Write a print statement to display the value stored in the variable author
Python
Need a hint?

Use print(author) to show the author's name on the screen.