โ“ Dictionaries and Search Engine Optimization (SEO) ๐Ÿ‘€

# 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)

  1. Create a function that:

    • Creates a dictionary called metrics with 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

  2. 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")