Logic Errors 3
Word Problem: Write a function that returns the area of a circle given its diameter.
To solve this word problem, Sai defined the following function, which runs without any errors:
fun circle-area(diameter): num-sqr(diameter) * num-pi end
1 Can you see what is wrong with this definition?
To explain their thinking, they filled out the following Design Recipe:
Directions: Write a function that returns the area of a circle given its diameter.
Every contract has three parts… circle-area::Number->Number Given the diameter, multiply pi by radius squared to get the area
Write some examples, then circle and label what changes… examples: __circle-area (10)__ is num-sqr(10 / 2) * num-pi __circle-area (50)__ is num-sqr(50 / 2) * num-pi end
Write the definition, giving variable names to all your input values… fun area(diameter): __num-sqr(diameter) * num-pi 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.