At My Fingertips

Documentation

Clover

In this activity we are going to implement a function that generates a three-leaf clover or a four-leaf clover, like these ones:

clover

The first thing you will have to do is implement a leaf function, that, since leaves can be represented as hearts, will return a green heart.

We have an activity that will guide you through the implementation of a heart function, so we suggest solving that first, copy-pasting your code in here and adapting it so that the leaf function returns a heart of the given LEAF_COLOR color.

Loading...

Let's now implement the stem function that returns a rectangle of color LEAF_COLOR, with width of 1/5 compared to the given leaf_radius, and height of double the given leaf_radius

Loading...

The clover function

Let's now implement a clover function that will generate a three leaf clover or a four leaf clover, given the leaf_radius and a boolean value four_leaves.

If the four_leaves argument is True, the function should return a four-leaf clover, otherwise, it should return a three-leaf clover. Use conditional statements to work with boolean values!

There are two (among many more) suggested strategies:

  1. If you feel confident with repetition, you can use it to build a clover with 3 or 4 leaves, directly in the clover function
  2. If you don't want to use repetition, create two functions, one (for example called three_leaf_clover) that only generates a three leaf clover, and one (for example called four_leaf_clover) that only generates a four leaf clover, and then combine the solutions in the final clover function, where the output depends on the given boolean four_leaves
Loading...

You can now run the following cells to see your results!

Loading...
Loading...

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

Clover

Logo of PyTamaro

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

Privacy PolicyPlatform Version c08406b (Wed, 20 Nov 2024 12:30:00 GMT)