instagram

Students build on their knowledge of the image-scatter-plot function, motivating the need for if-expressions in their programming toolkit. This drives deeper insight into subgroups within a population, and motivates the need for more advanced analysis.

Prerequisites

Relevant Standards

Select one or more standards from the menu on the left (⌘-click on Mac, Ctrl-click elsewhere).

CSTA Standards
2-AP-19

Document programs in order to make them easier to follow, test, and debug.

2-DA-08

Collect data using computational tools and transform the data to make it more useful and reliable.

3B-NI-05

Use data analysis tools and techniques to identify patterns in data representing complex systems

K-12CS Standards
6-8.Data and Analysis.Inference and Models

People transform, generalize, simplify, and present large data sets in different ways to influence how other people interpret and understand the underlying information. Examples include visualization, aggregation, rearrangement, and application of mathematical operations.

9-12.Algorithms and Programming.Control

Programmers consider tradeoffs related to implementation, readability, and program performance when selecting and combining control structures.

P3

Recognizing and Defining Computational Problems

Next-Gen Science Standards
HS-SEP4-5

Evaluate the impact of new data on a working explanation and/or model of a proposed process or system.

Lesson Goals

Students will be able to…​

  • use if-then-else expressions in Pyret

  • explain the behavior of a (specific) higher order function

Student-facing Lesson Goals

  • Let’s explore functions that behave differently based on the input.

Materials

Preparation

  • Make sure all materials have been gathered

  • Decide how students will be grouped in pairs

  • Computer for each student (or pair), with access to the internet

  • Student workbook, and something to write with

  • All students should log into CPO and open the "Animals Starter File" they saved from the prior lesson. If they don’t have the file, they can open a new one

Supplemental Resources

Language Table

Types

Functions

Values

Number

num-sqrt, num-sqr

4, -1.2, 2/3

String

string-repeat, string-contains

"hello", "91"

Boolean

==, <, <=, >=, string-equal

true, false

Image

triangle, circle, star, rectangle, ellipse, square, text, overlay, bar-chart, pie-chart, bar-chart-summarized, pie-chart-summarized

πŸ”΅πŸ”ΊπŸ”Ά

Table

count, .row-n, .order-by, .filter, .build-column

🔗Warmup

Age v. Weeks Scatterplot Age v. Weeks Scatterplot🖼Show image

  1. Show students this code, which uses image-url and scale to generate icons of animals.

  2. What do they Notice? What do they Wonder? How might this scatterplot change our analysis?

  3. Have students make a scatter plot of animals, using age as the x-axis values and weeks as the y-axis.

(For now, the scatter plot is purely to give students practice with contracts and displays. They are not expected to know much about scatter plots at this point.)

🔗If-Expressions 20 minutes

Overview

Students explore a program that makes use of an if-expression, develop their own understanding, and modify it.

Launch

So far, all of the functions we know how to write have had a single rule. The rule for gt was to take a number and make a solid, green triangle of that size. The rule for bc was to take a number and make a solid, blue circle of that size. The rule for nametag was to take a row and make an image of the animal’s name in purple letters.

What if we want to write functions that apply different rules, depending on the input? For example, what if we want to change the color of the nametag depending on the species of the animal?

Investigate

Synthesize

Have the class share their own explanations for how if-expressions work.

Pyret allows us to write if-expressions, which contain:

  1. the keyword if, followed by a condition.

  2. a colon (:), followed by a rule for what the function should do if the condition is true

  3. an else:, followed by a rule for what to do if the condition is false

We can chain them together to create multiple rules, with the last else: being our fallback in case every other condition is false.

🔗Better Image Scatter Plots 20 minutes

Overview

Suppose we want to make a scatter plot for the Animals Dataset, but with each dot being a different color depending on the species. This would make it possible to see if different animals are "clustered" in different parts of the plot.

Investigate

Have students open Word Problem: species-color (Page 38). Make sure they all write the Contract and Purpose Statement first , and check in with their partner and the teacher before proceeding.

Once they’ve got the Contract and Purpose Statement, have them come up with examples: for each species. Once again, have them check with a partner and the teacher before finishing the page.

Once another student and the teacher has checked their work, have them type this function into their animals starter files, and use it to make an image-scatter-plot using age as the x-axis and weeks as the y-axis.

Synthesize

Age v. Weeks Scatterplot Age v. Weeks Scatterplot🖼Show image

  1. What do you Notice about this scatter plot?

  2. What do you Wonder?

What does this new visualization tell us about the relationship between age and weeks? What other analysis would be helpful here?

🔗Closing

Make sure to direct the conversation back to Data Science! Does this scatter plot make us think we should be analyzing animals separately? What other scatter plots might this be useful for?

This scatterplot makes it clear that we may want to analyze each species separately, rather than grouping them all together! In the next lesson, students will learn how to do just that.

These materials were developed partly through support of the National Science Foundation, (awards 1042210, 1535276, 1648684, and 1738598). CCbadge Bootstrap:Data Science by Emmanuel Schanzer, Nancy Pfenning, Emma Youndtsmith, Jennifer Poole, Shriram Krishnamurthi, Joe Politz, Ben Lerner, Flannery Denny, and Dorai Sitaram with help from Eric Allatta and Joy Straub is licensed under a Creative Commons 4.0 Unported License. Based on a work at www.BootstrapWorld.org. Permissions beyond the scope of this license may be available by contacting schanzer@BootstrapWorld.org.