# More engaging word problems with code

Word problems are an important part of doing mathematics. They require higher-level thinking than procedural problem-solving. They get students into the Standards of Mathematical Practice, especially:

#### CCSS.MATH.PRACTICE.MP7 Look for and make use of structure.

Consider this word problem, taken from Connected Mathematics: Moving Straight Ahead.

In 1990, Beate Anders of East Germany set the women’s world record for the 3000 meter walk. She completed the race in 11 minutes, 59.36 seconds. In 1991, Kerry Ann Saxby of Australia beat Anders’ record. She completed the 3000-meter walk in 11 minutes, 51.26 seconds.
a) What was Anders’ average walking speed?
b) How much faster did Saxby walk than Anders?

A student solving this problem has to identify the structure of the problem as one of unit rates in which unit conversions are needed, and then decide which calculations to perform and check the reasonableness of the answers. It’s a good problem, and a valid real-life situation.

But we could hit more of the Standards of Mathematical Practice, by changing the task slightly.

Beate and Kerry are race walkers. Beate walked a 5k race and finished it in 20 minutes, 10.15 seconds. Kerry finished a 3k race in 11 minutes, 51.26 seconds. Write a computer program that asks you for the distance walked by two race walkers and their race times in minutes and seconds, and tells you who the faster walker was.

The math in this word problem is exactly the same, but the thinking is quite different. The student has to identify the structure of the problem, and also identify variables, create a model of the problem using the variables, create an algorithm that solves the problem by breaking down the solution process into steps, write the program, and test it with input that gives her an expected answer.

In other words, we’re now hitting these standards of mathematical practice in addition to MP7. The student how has to create a model and verify its correctness. Depending on the structure of the task, you could hit many more.

#### CCSS.MATH.PRACTICE.MP4 Model with mathematics.

I taught a summer class on coding for girls, and included some modified word problems in one of their first programming challenges. The girls completed the challenges with a partner and did some really clever things – they loved being able to integrate characters, animation, and a storyline with their math scenarios. Here are their challenges and solutions.

Challenge 1:
Kanye has a rectangular hot tub, but he’s under water restrictions, so he needs to keep track of how many gallons of water he’s using. Kim knows there are 231 cubic inches in one gallon. She should ask Kanye for the length, width, and height of his hot tub and store them as variables. Then, she should calculate how many gallons are needed to fill the hot tub.

Here’s one solution I got. Their implementation doesn’t have the ability to change the width, length, and depth of the tub, but it has an interesting math model with the conversion of cubic feet to cubic inches and then to gallons.

https://scratch.mit.edu/projects/67321406/

Challenge 2:

Ariel is going shopping for some new fashions. Her favorite Rodeo Drive store is having a 30% off sale, which is awesome. Tax in Beverly Hills is 9%. Eric should ask her how much the items are she’s buying, and then tell her the correct price after subtracting the discount and adding the tax.  He should use variables for the cost of the items she’s buying, and the total cost.

A lot of students were drawn to this problem and I got these different implementations.

These students re-used the “Cost Before” variable which was confusing to me, but probably efficient – and it does show they understand the concept that the variable’s value can change throughout the program.
https://scratch.mit.edu/projects/67321608/#editor

These students solved the problem in the fewest number of steps – calculating the discount in one step and then writing one long expression to calculate the final price. They spent the rest of the time designing an Ariel character that would make Mr. Disney proud.
https://scratch.mit.edu/projects/67320074/#editor

These students added some funny characters to their program – and at least one snarky comment from Ariel.
https://scratch.mit.edu/projects/67321198/#editor

Challenge 3: Based on my very real experience at Carpet Exchange.
Fluffy is getting new carpet installed in her apartment. She knows the length and width of her family room and bedroom. When she goes carpet shopping, she finds out the carpet she wants is \$3.50 per square foot, and padding is \$5 per square yard (there are 9 square feet in a square yard). Also, there’s a \$250 installation fee.  Fluffy should use variables for the length and width of the family room, and calculate the total cost of the carpet.

These students completed the challenge effortlessly. If I’d had a little extra time with them, they could have modified the program to ask you for the dimensions of more than one room.
https://scratch.mit.edu/projects/67321374/#editor

A screen shot of the Carpet program.

When I work with my 7th and 8th graders in Computer Science, we do word problems in a text-based programming language such as JavaScript. One of the first challenges we do when we learn about “if” statements is very similar to the Beate / Kerry situation at the beginning of this post.

A fun activity my students like is an “I have… Who has…” race. We see which class can finish the race the fastest. However, sometimes my classes are different sizes. Recently, a class of 28 students finished the challenge in 1 minute, 38 seconds. A class of 33 students finished in 1 minute, 50 seconds. Which class was actually faster?  Write a program that will let you input the number of students in each class, and the minutes and seconds each class took to complete the race. Decide which class was faster and display a message saying who won!

The problem involves a unit conversion, calculating a unit rate, and then understanding how to compare the unit rates (students per second or seconds per student). This is one implementation of the problem in JavaScript, using variables.