Lab 2: Functions and Modules
Learning Outcomes
Learning Outcomes
- Gain experience writing Python functions.
- Gain experience using online documentation for Python modules.
- Intro video
- Download lollipop.py
- Modify the program such that 100 random lollipops are drawn. A random lollipop should have a radius between 10 and 30 pixels and a stick that is the same length as the lollipop's diameter. The position of the lollipop should be randomly determined such that it can appear anywhere within the 600 by 600 border. (Note: this includes touching the border without going outside the border.) This picture shows one possible outcome of a correct solution.
- 2 points - A Python function named draw_lollipop is defined (1 point) and called 100 times (1 point).
- 2 points - The function draws a lollipop (1 point) and its stick (1 point) correctly.
- 2 points - The radius of the lollipop is calculated correctly.
- 2 points - The range of x values for the lollipop and its stick are calculated correctly.
- 2 points - The range of y values for the lollipop and its stick are calculated correctly.
- The possible range of x and y coordinates for the lollipop and stick can be determined once the the lollipop's radius is determined.
- Once the range is known, a value in that range can be randomly generated by using a function that appears in the random module documentation.