Sure! Below is an example of a Python script that creates two dictionaries, each with at least 10 key-value pairs. I've added comments throughout the code to explain each part.
# Create the first dictionary containing information about a book
book_info = {
'title': 'To Kill a Mockingbird', # Title of the book
'author': 'Harper Lee', # Author of the book
'year_published': 1960, # Year the book was published
'genre': 'Fiction', # Genre of the book
'pages': 281, # Number of pages in the book
'language': 'English', # Language the book is written in
'isbn': '978-0-06-112008-4', # ISBN number of the book
'publisher': 'J.B. Lippincott & Co.', # Publisher of the book
'rating': 4.27, # Average rating of the book
'review_count': 500000 # Number of reviews for the book
}
# Create the second dictionary containing personal characteristics
person_info = {
'name': 'John Doe', # Name of the person
'age': 30, # Age of the person
'gender': 'Male', # Gender of the person
'occupation': 'Engineer', # Occupation of the person
'hobbies': ['Reading', 'Cycling', 'Hiking'], # List of hobbies
'city': 'New York', # City where the person lives
'is_student': False, # Whether the person is a student
'nationality': 'American', # Nationality of the person
'height_cm': 175, # Height of the person in centimeters
'weight_kg': 70 # Weight of the person in kilograms
}
# Print both dictionaries to verify their contents
print("Book Info:", book_info) # Output the book_info dictionary
print("Person Info:", person_info) # Output the person_info dictionary
Explanation of Code Sections:
-
Creating the First Dictionary (
book_info
):- Each key corresponds to a specific attribute of a book, and the values provide relevant details for those attributes.
-
Creating the Second Dictionary (
person_info
):- Similar to the first dictionary, this one holds various attributes related to a person.
-
Printing the Dictionaries:
- The last section of the code outputs the contents of both dictionaries to the console, so you can see what was stored.
How to Use This Code:
You can copy and paste this Python code into a new file in your PythonAnywhere environment. After saving the file, you can run it to see the output with the defined dictionaries.