At My Fingertips
Rapid Playground
In this activity we are going to implement a function that generates a three-leaf clover or a four-leaf clover, like these ones:
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.
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
Let's now implement a clover
function that will generate a three leaf clover or a four leaf clover, given the parameters leaf_radius
and boolean value four_leaves
.
If the four_leaves
value 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 suggested strategies:
clover
functionthree_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
You can now run the following cells to check your results!
This activity has been created by LuCE Research Lab and is licensed under CC BY-SA 4.0.
Clover
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)