At My Fingertips

Documentation

Simple Popsicle

Let's create a function that can produce popsicles like these:

strawberry popsicle

Decompose

We could say it is a watermelon popsicle, but that's not really describing the composition.

How about:

  • watermelon-colored ice on top
  • a wooden stick at the bottom
  • the ice has a rounded edge at the top
  • the stick has a semicircle at the bottom

Measurement

The popsicle is symmetric. It has width w, and an overall height 3w.

The ice has a total height of 2w and is as wide as the overall popsicle. The radius of the top edge of the ice is w/4.

The stick has total height w and a width w/4. The semicircle at the bottom of the stick has radius w/8.

Import Rounded Edge Function

To create the ice, we want to have a rounded edge.

If you do not yet have a rounded_edge function in your toolbox, solve the PyTamaro iconRounded Edge activity to create one.

Then import your rounded_edge function from your toolbox.

Loading...

Implement

Note: We defined the stick_color as a constant inside the function. Any popsicle created by this function will have a stick in that same color, and nobody outside that function needs to know about that color.

The ice_color, though, is a parameter: we want to create different kinds of popsicles, with differently colored (and tasting) ice!

Loading...

Play With Parameters

Try to create popsicles in different sizes and colors. Try the given lime color. Can you create a realistically looking orange? A chocolate brown?

Loading...

Save in Toolbox

If you like your simple_popsicle function, save it in your toolbox.


This activity has been created by LuCE Research Lab and is licensed under CC BY-SA 4.0.

Simple Popsicle

Logo of PyTamaro

PyTamaro is a project created by the Lugano Computing Education Research Lab at the Software Institute of USI

Privacy Policy • Platform Version 1cd5229 (Tue, 05 Nov 2024 16:55:57 GMT)