Referenced from lesson Defining Functions

Directions: For each of the following collections of Examples, write the contract for the function above the examples.

  1. :: ->
    examples: third-root(16) is expt(16, 1/3) third-root(125) is expt(125, 1/3) third-root(625) is expt(625, 1/3) end

  2. :: ->
    examples: sentence-length("hello", 5) is string-length("hello") + 5 sentence-length("please", 6) is string-length("please") + 6 sentence-length("goodbye", 10) is string-length("goodbye") + 10 end

  3. :: ->
    examples: upside-down(triangle(50, "solid", "yellow")) is rotate(180, triangle(50, "solid", "yellow")) upside-down(star(150, "solid", "blue")) is rotate(180, star(150, "solid", "blue")) end

  4. :: ->
    examples: product-squared(5, 6) is sqr(5 * 6) product-squared(10, 17) is sqr(10 * 17) product-squared(2, 5) is sqr(2 * 5) end

  5. :: ->
    examples: half-image("www.images.com/cat_image") is scale(0.5, bitmap/url("www.images.com/cat_image")) half-image("www.images.com/dog_image") is scale(0.5, bitmap/url("www.images.com/dog_image")) end

  6. :: ->
    examples: triple(4) is 4 * 3 triple(10) is 10 * 3 triple(3) is 3 * 3 end

These materials were developed partly through support of the National Science Foundation, (awards 1042210, 1535276, 1648684, and 1738598). CCbadge Bootstrap:Integrated Oklahoma by Jen Poole is licensed under a Creative Commons 4.0 Unported License. Based on a work at www.BootstrapWorld.org. Permissions beyond the scope of this license may be available by contacting schanzer@BootstrapWorld.org.