The context is the high-level description of an exercise that provides details on the learning objective of the exercise, what the student is about to solve, and why. Any relevant background information goes in here. 

Contextualizing the exercises also contributes to the course narrative by tying in the dataset. Furthermore, contextualizing your exercise helps students understand why the exercise is useful and provides a reference for them when they find themselves in a similar situation out in the wild.

Think about the learning objective

Each exercise should have a single measurable learning objective. Think about how the context contributes to teaching it. Make sure this learning objective is evident in your context.

Motivate the exercise

If students don't know why they are doing a task, it can seem like a waste of time. Motivating the exercise by adding a sentence to explain why the task is useful, or what problem it solves, can motivate the student.

Example from Interactive Maps with leaflet, "A map with a narrower view"

We can limit users' ability to pan away from the map's focus using the options argument in the leaflet()function. By setting minZoom anddragging, we can create an interactive web map that will always be focused on a specific area.

leaflet(options = 
        leafletOptions(minZoom = 14, dragging = FALSE))  %>%
  addProviderTiles("CartoDB")  %>%
  setView(lng = -73.98575, lat = 40.74856, zoom = 14)

Alternatively, if we want our users to be able to drag the map while ensuring that they do not stray too far, we can set the maps maximum boundaries by specifying two diagonal corners of a rectangle.

Explain when this task would occur in real life

Sometimes it isn't obvious to students when a task should be performed (or when it shouldn't). The context section is a great place to talk about this.

Example from Intermediate Functional Programming with purrr, "Refreshing your purrr  memory"

Let's pretend you're a data analyst working for a web agency. The web-design team has been running a weeklong A/B test that compares the performance of two design proposals for a website, and you're now in charge of analyzing the results.

The team measured the number of visits to the Contact page to determine the design's impact on the number of people contacting the company. These designs were presented to 2/3 of visitors.

visit_a  contains the results from campaign A and visit_b the results of campaign B. Both are expressed as an average hourly number of visits. All the other stats you have are expressed as visits per day, so you need to convert these two. Then, you'll extract the mean of each vector.

Talk about the dataset

You spent a lot of time during course design choosing the perfect dataset, talk about it! If you have fun datasets, make sure to play them up and get students interested and invested in your course. 

Example from Python for MATLAB Users, "How much more do organic avocados cost?"

Avocados are increasingly popular food, and no city in the United States consumes as many avocados as Los Angeles, California. At the same time, high demand for organic produce means that organic avocados cost more than their conventionally grown counterparts. In this exercise, you'll explore some historical data on the price of avocados in Los Angeles to gain some insight into the premium that people pay for organic avocados.

Two arrays, conventional and organic, are loaded that contain the month-by-month average price in USD of conventional and organic avocados in Los Angeles.

You'll use NumPy's mean(), min(), and max() functions to summarize these arrays and gain some insight into the premium cost of organic avocados in Los Angeles.

Did this answer your question?