(Also available in Pyret)
Students take a closer look at how functions can work together by investigating the relationship between revenue, cost, and profit.
Lesson Goals |
Students will be able to:
|
Student-Facing Lesson Goals |
|
Materials |
|
Supplemental Materials |
|
Key Points for the Facilitator |
|
🔗Problem Decomposition 30 minutes
Overview
Students are introduced to word problems that can be broken down into multiple problems, the solutions to which can be composed to solve other problems. They adapt the Design Recipe to handle this situation.
Launch
-
What do you Notice?
-
What do you Wonder?
One example of a relationship that surfaced from Sally’s brainstorming is that every glass sold incurs costs. Sally will need to buy lemons, sugar, powdered drink mix, cups, and water.
-
What other relationships can you find?
-
Below are some possible observations students might share; it’s okay if students are not confident using terms such as cost, revenue, and profit!
-
Every glass sold brings in $1.75 in revenue.
-
Every glass sold brings in some amount of profit: it costs a certain amount to make, but it brings in another amount in revenue.
-
The total cost of the bike will be depend on the tax rate.
-
In order to figure out how many lemonade sales it will take to pay for the bike, we’d need to to divide the cost (with tax) by the profit per glass.
-
Investigate
-
Define functions for
revenue
andcost
on Word Problems: revenue, cost. Note: The information you need to write thecost
function is provided in the Design Recipe word problem! -
Once you’ve defined the functions, open Sally’s Lemonade Starter File.
-
Enter your code for
revenue
(including all examples and definitions) below the first prompt. -
Enter your code for
cost
below the second prompt. -
Click "Run" and make sure your tests pass.
-
What is the difference between revenue and profit?
-
Revenue is the total amount of money that comes in, profit is the remaining money after cost has been subtracted.
-
-
How could Sally increase her profits?
-
By decreasing her costs, raising her prices (which increases revenue), by selling more lemonade.
-
-
What is the relationship between profit, cost, and revenue?
-
Profit = Revenue - Cost
-
Ensure that students have correctly defined the functions for revenue
and cost
before moving onto the next task - using the Design Recipe to define profit
. While students are working, walk the room and gauge student understanding. There is more than one way to write the profit
function! Encourage discussion between students and push them to develop their thinking on the advantages and disadvantages of each correct solution.
-
Complete Word Problem: profit, using the Design Recipe.
-
Note: There are multiple correct solutions!
-
-
Add your code for
profit
in Sally’s Lemonade Starter File below the third prompt; be sure to type all examples and definitions. -
Click "Run". Do all your tests pass?
As students finish, or for homework, you may also want them to figure out how many cups of lemonade Sally would have to sell in order to buy her bike using Sally’s Bike.
We just modeled Sally’s lemonade business with functions. One part of the model was profit, which can be written several ways.
Turn to Profit - More than one Way! and consider the four function definitions presented.
The four definitions of profit
from this page are shown here:
(define (profit g) (- (* 1.75 g) (* 0.3 g)))
(define (profit g) (* (- 1.75 0.3) g))
(define (profit g) (* 1.45 g))
(define (profit g) (- (revenue g) (cost g)))
-
Which of these four
profit
definitions do you think is "best", and why?-
Possible arguments: The first one is "closest to the word problem". The third one is "fastest", with the computation already completed. The last one is the most readable.
-
-
Did anyone have additional ideas for how to define a
profit
function? -
If lemons get more expensive, which definitions of
profit
need to be changed?-
Every definition except the last one would need to be changed.
-
-
If Sally raises her prices, which definitions of
profit
need to be changed?-
Every definition except the last one would need to be changed.
-
-
Which definition of
profit
is the most flexible? Why?-
The last definition is the most flexible; it can be used with any revenue and cost functions.
-
profit
can be decomposed into a simpler function that uses the cost
and revenue
functions.
Decomposing a problem allows us to solve it in smaller pieces
Synthesize
We saw that there are many "correct" ways to define a profit function for Sally’s Lemonade Stand.
-
Why would programmers prefer to define
profit
using other functions than put all of the collections in the definition ofprofit
itself?-
Smaller pieces are easier to think about, and to test!
-
Pieces can be reused!
-
Like Lego pieces, smaller functions can be used to build all kinds of things.
-
-
Reusing code means less code overall.
-
Less code means fewer places to make (and fix) mistakes.
-
-
Reusing code means less duplicate code.
-
When code needs to be changed, that change only needs to made in one place, instead of in multiple places.
-
-
🔗Top-Down vs. Bottom-Up 20 minutes
Overview
Students explore problem decomposition as an explicit strategy, and learn about two ways of decomposing.
Launch
Top-Down and Bottom-Up design are two different strategies for problem decomposition.
Bottom-Up: start with the small, easy relationships like revenue
and cost
first. How are they connected with the outer circle? You’ll get there eventually, but we can leave it blank for now (…
). In the Lemonade Stand, you defined cost
and revenue
first, and then put them together in profit
. This is the same approach as building your Circle of Evaluation inside-out!
Top-Down: start with the "big picture" and then worry about the details later. We could have started with profit
as (- revenue cost)
, and fill in the details of revenue
and cost
later (thus the …
). This is the same approach as building your Circle of Evaluation outside-in!
Investigate
Consider the following situation:
Jamal’s trip requires him to drive 20mi to the airport, fly 2300mi, and then take a bus 6mi to his hotel. His average speed driving to the airport is 40mph, the average speed of an airplane is 575mph, and the average speed of his bus is 15mph. Aside from time waiting for the plane or bus, how long is Jamal in transit?
Take a moment to think:
-
What would your first step be if you were trying to figure out how long Jamal would be in transit?
-
What circles would you draw or functions would you define to solve this?
-
Would you work top-down or bottom-up?
Then turn to Top Down or Bottom Up.
-
Who used a top-down strategy, Bear or Lion? How do you know?
-
Lion’s strategy is top-down because it starts with the big picture function: In-Transit Time and defines it using words representing the smaller pieces.
-
In contrast, Bear starts working with numbers right away.
-
Synthesize
-
Do you have questions about either of these strategies?
-
Which strategy to do you prefer? Why?
Make sure that students see both strategies. Even if students have a preference for one strategy, there will be instances when the other strategy is easier to work with.
These materials were developed partly through support of the National Science Foundation, (awards 1042210, 1535276, 1648684, 1738598, 2031479, and 1501927).
Bootstrap by the Bootstrap Community is licensed under a Creative Commons 4.0 Unported License. This license does not grant permission to run training or professional development. Offering training or professional development with materials substantially derived from Bootstrap must be approved in writing by a Bootstrap Director. Permissions beyond the scope of this license, such as to run training, may be available by contacting contact@BootstrapWorld.org.