Logic Errors
Word Problem: It’s normal to tip 20% on a bill at a restaurant. Write a function that takes in the total on the bill, and returns the new total that adds a 20% tip.
To solve this word problem, Zahara defined the following function, which runs without any errors:
fun check-total(bill): 0.2 * bill end
1 Can you see what is wrong with this definition?
To explain their thinking, they filled out the following Design Recipe:
Directions: It’s normal to tip 20% on a bill at a restaurant. Write a function that takes in the total on the bill, and returns the new total that adds a 20% tip.
Every contract has three parts… check-total::Number->Number Returns the total of a check with 20% of the cost added
Write some examples, then circle and label what changes… examples: __20 ()__ is 0.2 * 20 __56.67 ()__ is 0.2 * 56.67 end
Write the definition, giving variable names to all your input values… fun check-total(bill): __0.2 * bill end |
2 Read each step in the recipe carefully. In which step did their thinking first go wrong? (circle one)
Contract & Purpose |
Examples & Labels |
Definition |
3 What could they have done to find or avoid the mistake in the first place?
These materials were developed partly through support of the National Science Foundation, (awards 1042210, 1535276, 1648684, and 1738598). 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.