# You must make sure to run all cells in sequence using shift + enter or you might encounter errors
from pykubegrader.initialize import initialize_assignment
responses = initialize_assignment("10_dictionaries_q", "week_2", "readings", assignment_points = 11.0, assignment_tag = 'week2-readings')
# Initialize Otter
import otter
grader = otter.Notebook("10_dictionaries_q.ipynb")
โ Dictionaries and Search Engine Optimization (SEO) ๐#

Search Engine Optimization (SEO) is the practice of improving a website to increase its visibility in search engines like Google. It involves tracking various metrics (measurements) about how people interact with your website:
What is SEO?
Search Engine Optimization (SEO) is the practice of improving a website to increase its visibility in search engines like Google. It involves tracking various metrics (measurements) about how people interact with your website:
Pageviews: Number of times people view your pages ๐
Bounce Rate: Percentage of visitors who leave without interacting ๐ช
Keywords: Words people use to find your site ๐
Rankings: How high your site appears in search results ๐
# Run this block of code by pressing Shift + Enter to display the question
from questions._10_dictionaries_q import Question1
Question1().show()
# Run this block of code by pressing Shift + Enter to display the question
from questions._10_dictionaries_q import Question2
Question2().show()
# Run this block of code by pressing Shift + Enter to display the question
from questions._10_dictionaries_q import Question3
Question3().show()
Website Analytics Exercise ๐#
Instructions:#
Letโs practice working with dictionaries by creating a simple analytics dashboard!
Context
Weโll create a function that manages website metrics. Donโt worry about the SEO terms - focus on practicing dictionary operations!
Pageviews = Number of times people view your pages
Bounce rate = Percentage of visitors who leave quickly (shown as decimal)
Session duration = How long visitors stay (in seconds)
Create a function that:
Creates a dictionary called
metricswith these key-value pairs:โpageviewsโ: 1000
โbounce_rateโ: 0.35
โdurationโ: 180
Adds a new key โdateโ with value โ2024-03-15โ
Calculates the bounce rate as a percentage (multiply by 100)
Returns the dictionary and the percentage
The function should print:
Website Metrics for 2024-03-15: - Pageviews: 1000 - Bounce Rate: 35% - Average Duration: 180 seconds
We have provided this code for you.
def website_analytics():
# Create the `metrics` dictionary
...
# Add the date
...
# Calculate percentage bounce rate and save it to a variable called `bounce_rate_percent`
...
return metrics, bounce_rate_percent
# Call the function
metrics, bounce_rate_percent = website_analytics()
# We have provided this code for you, you don't need to modify it
# Print the summary
print(f"Website Metrics for {metrics['date']}:")
print(f"- Pageviews: {metrics['pageviews']}")
print(f"- Bounce Rate: {int(bounce_rate_percent)}%")
print(f"- Average Duration: {metrics['duration']} seconds")
grader.check("question-Website-Analytics")
Submitting Assignment#
Please run the following block of code using shift + enter to submit your assignment, you should see your score.
from pykubegrader.submit.submit_assignment import submit_assignment
submit_assignment("week2-readings", "10_dictionaries_q")