Exercise Types

Examples of the types of exercises we commonly use in these tutorials

This list isn't exhaustive. These are some ideas to get you started. Remember, exercises can be straightforward and simple. This is a quick tutorial - not a quarter long course where you're writing homework assignments.

Copy and Paste; Change One Thing

This is the most common exercise we write. While the specific code varies based on the workshop topic, to successfully complete the exercise, all the learner needs to do is copy a line of code (or few lines of code) from the teaching materials section of the tutorial and change one thing about the code. The one thing they change could be:

  • Use a different dataset or variable (easy)

  • Change the column (easy)

  • Write a different conditional expression (harder, likely requires prerequisite knowledge)

  • Use a different summary function (medium)

  • Change the color/line type/other visual element of a plot (medium)

  • Choose a different subset (medium)

  • Change the function name to a similar, related function (easy, if you give them the function name)

  • Change the value of an input (depends)

This is our baseline exercise, and it's usually the first type of exercise we use in a tutorial. We often either tell learners (verbally, usually not in the written exercise) that they may want to copy and paste an example above to start from, or we copy and paste ourselves when we show the answer.

Why we like this:

  • Builds confidence for hesitant learners.

  • Normalizes copying and pasting and then adapting code examples, something we all do. Sets them up to use the tutorial materials in the future for their own use cases: helps them realize they can copy and paste your examples and adapt them to their own datasets or use cases as well.

  • Makes sure that learners understand what each component of the code you've just showed them does -- they need to change the right component.

  • It's a quick exercise. If you are trying to fit 6 exercises into an hour, some need to be quick.

How you can vary this:

  • Copy and Paste; Change Two or Three Things: as the tutorial progresses and people become more familiar with the material, ask them to do more in each exercise. Alternatively, if you know you have an intermediate or advanced audience, you may be able to ask them to do more than one thing from the start.

  • For tutorial on using a tool/interface, learners won't be copying and pasting code, but you can ask them to do something you just did, with one alteration. For example, choose a different option in a dialogue box, repeat the steps for a different dataset or variable, etc.

  • Provide a challenge question for those who can complete the exercise quickly. Ask them to change multiple things, while most learners are just changing one. Ask them to try a use case that you didn't cover, such as a different type of data or missing data. But be prepared to go over the answer to the challenge question as well.

  • Have learners change 2-4 things about an example above, but do it one step at a time as a multi-part exercise. Example: First change the column, then change the subset, then change this input value.

Fill in the Blanks

Provide the code they need to complete the exercise, but with blanks in it (use some stand-in such as ---- for the blanks) that they need to replace with the correct pieces of code. This works well early in a tutorial when learners may be getting used to a new syntax or workflow, and that syntax or workflow may be a little complicated or prone to syntax errors. Or when learners need multiple lines of code to complete an exercise, but you want them to just focus on a few key parts.

When this doesn't work: fill in the blank doesn't work well if you're focusing on syntax. It does work well if you want learners to focus on what the inputs to a function might be: variable names, column names, choose the correct function to use, numbers, etc. The blanks should be filled in with words/names/numbers, not pieces of syntax (curly braces, colons) or operators (+, %%).

How you can vary this: instead of copy and paste, or fill in the blanks, copy and paste code you just showed them as starter code for the exercise. Then tell them to change the code to work with a different dataset/variable/column/function/number/etc. This makes the copy and paste exercise explicit, and it functions like a fill-in-the-blank exercise but starts with code that is actually complete.

Read the Documentation

Want your learners to get more acquainted with the documentation? Write an exercise that requires them to do just that. Example: Look at the documentation/help page/cheatsheet for functionname. Find the argument that will let you ____. Change the code below to do something different.

Make sure that you've shown learners how to access the documentation prior to the exercise. And that learners know how to find relevant information in the documentation (you may need to walk them through how to read a documentation page). Consider showing them again how to get to the specific page they need as the exercise starts. Be clear about the output you want them to produce.

Focus on finding one piece of information in the documentation and altering code to use that one piece of information. For "altering" code, you could be expecting them to copy and paste from your teaching materials, or give them code to alter as starter code.

Why we like this: helps learners get in the habit of looking at and reading the documentation themselves. Helps them learn how to parse technical language them may not be used to and find the information they need.

Learn to Search for Answers

Want to encourage your learners to solve problems on their own? Ask them to do something you haven't explicitly taught them, but that you know there are good examples of and resources for online.

Example: Search the internet to find out how to ____. Then write the code to do this below. Share successful search terms you used in the chat.

Keys to success:

  • It will be reasonably easy for learners to find good answer. Misleading answers aren't among the top search results. Make sure to test the search on an anonymous browser so that the search results you see are closer to what your learners will see (yours are likely already geared towards the site you use regularly and the topics you read about).

  • You clearly define a simple task that you want learners to do.

  • You have given learners some tips or suggestions on searching that will make them more successful.

  • You explicitly tell them that they need to search the internet for an answer -- that you haven't taught them what they need to know.

  • That you would actually search the internet for the answer instead of looking at the documentation.

  • This is a beginner or intermediate workshop where there is value in teaching this type of skill and encouraging learners to become confident in solving their own problems. Advanced learners should already have this skill, so no need to teach it.

  • Don't ask them to search for an error message. Parsing search results for resolving error messages is an advanced skill that is likely beyond what you want to teach with this type of exercise in a tutorial.

Correct the Error

Provide code that produces an error. Ask learners to fix the error. Example: The code below produces an error. Run the code to see the error. Then fix the the code so that it runs without error and produces a specified output.

Stick to one error at a time except with advanced learners. Even with advanced learners, if there is more than one error, tell them how many errors there are. Finding multiple errrors at once (generally troubleshooting code) works better as an in-person group exercise than a solo exercise in a virtual workshop.

How you can vary this: Give code that produces an incorrect (but not error-producing) result. Be very clear about what is wrong with the output as is, and what the correct output should look like. Have learners alter the code to produce the desired result.

Do X with what we learned instead/Rewrite this code

This exercise type presents the learner with some code that is functional, but that could be improved in some way or just done in a different way with the package or technique that you are teaching.

Examples:

  • Subset a data frame with filter and select functions instead of [] notation

  • Turn this loop into a function

  • Use the vectorized function we just learned to do this instead of looping over your array

  • Use the "or" operator instead of a character class to write this regular expression

Keys to success:

  • Learners should be familiar with the syntax and approach in the code that they are adapting -- they should understand what the code is doing. Otherwise they may not know that they are trying to achieve with the new skills that they learned. So make sure that the starting code would be understood with prerequisite knowlege for the workshop, or that it is code that you've shown or taught earlier in the tutorial.

  • In explaining the answer after learners do the exercise, discuss when you would use one option over another. Is one way always preferred? Is it just a matter of choice? Is one way to do this more efficient?

  • This isn't a large code refactoring exercise! Remember that the code the learner needs to write for the exercise should be just 1 (ideal) to ~3 lines of code.

Multiple Choice

When used as part of a one-hour tutorial, multiple choice questions that provide different code options that people can run to test out as answers to a question can work well. This is a good way to let people see how variations in code may result in different answers. Ask learners to choose the option that achieves some specified output. You aren't trying to trick them: you're letting them explore how changes to the code can result in different answers or errors.

Variation: encourage them to choose their answer without running the code, and then run the code only to check if their choice was correct.

If there is a concept that you need to cover as part of your tutorial that doesn't lend itself to a coding exercise, a multiple choice question covering some theoretical concept could also work. Writing effective multiple choice questions takes practice. Ideally, each wrong answer should allow you to address a misconception or mistake that a learner may have made. Simple multiple choice questions can test a learner's recall (e.g. Which function do we use for ___?), but this only works well if time has passed since they were exposed to the concept being tested; there isn't enough time in a one-hour tutorial for this gap.

We are more likely to use multiple choice questions as part of a review quiz between sessions in a workshop series, or as part of a help session/office hours during a Language Basics week of workshops. They can be a quick way to review the material you covered in the last session, or help learners check their understanding of key concepts you covered. Online quiz tools can make the review interactive, but we recommend against making the review a contest.

Data Visualization Critique

Teaching a data visualization workshop where you want to emphasize good data visualization practices and not just the code to create visualizations? Have learners critique a data visualization by typing answers to a few prompts in a shared document. Possible prompts:

  • What is working well?

  • What could be done better?

  • What feedback would you give?

  • What message do you take away from this visualization.

This exercise will take longer to complete than most coding exercises.

Last updated