At My Fingertips

Documentation

In this activity you will implement a function that can create a Pac-Man with an arbitrarily wide open mouth.

pacman

A pacman Function

Your function will have two parameters:

def pacman(radius: float, mouth_angle: float) -> Graphic

The size of the resulting Pac-Man should be determined by the given radius, and the mouth of the Pac-Man should open according to the given mouth_angle.

The assertions in the following code ensure that the pacman function will complain if it is called with a mouth angle that is negative or larger than 180°.

Complete the third assertion, to ensure that the given radius is valid: the value of the radius shouldn't be negative.

Then use circular_sector and rotate to construct the Pac-Man.

Loading...

What You Learned

You composed a graphic by creating a rotated version of a circular sector.

In terms of programming language features, you practiced implementing a function, and you learned to specify assertions to check a function's preconditions (i.e., to check that the values received via the parameters are acceptable). Your preconditions were Boolean expressions (expressions that evaluate to either True or False), and you used comparison operators to construct those expressions.


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

Pac-Man

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)