Using conditionals to understand rates
Computer programs start to become more interesting, interactive, and powerful when you can create the ability for them to make decisions. The conditional is a key concept! The ability to take one of two paths, to make a yes/no decision, is crucial to computing and algorithmic problem solving.
This lesson weaves rates in with conditionals. Relevant standards:
CSTA:L2:CPP:5 Implement problem solutions using a programming language, including: looping behavior, conditional statements, logic, expressions, variables, and functions.
Compute unit rates associated with ratios of fractions, including ratios of lengths, areas and other quantities measured in like or different units. For example, if a person walks 1/2 mile in each 1/4 hour, compute the unit rate as the complex fraction 1/2/1/4 miles per hour, equivalently 2 miles per hour.
Represent proportional relationships by equations. For example, if total cost t is proportional to the number n of items purchased at a constant price p, the relationship between the total cost and the number of items can be expressed as t = pn.
The students’ task, as explained in the video, is to write a program that can help solve a common dilemma for me as a teacher. If two classes are racing to complete a game, and the two classes take different amounts of time but also have different amounts of students, how do I determine who won? Variables and expressions could be used to calculate the rates, and then a conditional statement would determine which class won.
The students did pairs programming for this activity. Each group opened the starter program which has the task in the comments.
After the groups worked on the task, we discussed some of the solutions. There were two main approaches:
Approach 1: Calculate the time per student. Lowest amount of time per student wins.
Approach 2: Calculate the number of students per second. The greater number of students per second wins.
Some common misconceptions were: adding the seconds and minutes together and treating that as the total time (instead of converting the minutes to seconds and then adding), misunderstanding the rate of time per student vs. students per second, and failing to use parentheses in their rate calculation, so the order of operations would make division happen before addition. (example: rate = min * 60 + sec / students; rather than rate = (min * 60 + sec) / students;)
The students did a great job overall, and the level of challenge seemed appropriate for most. I truly think the mathematics and the programming were at a very appropriate level of challenge, but as we get deeper into programming, students need to be more metacognitive, they need to ask questions of each other, they need to be resourceful in finding answers – and many students lack those skills.
We will learn about boolean expressions next with these ideas in mind!