Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Week8 Assignment

Question 1
1.1 Please code a python module called area.py, which contains three functions:
a) rec_area() function that calculates and prints the area of a rectangle taking the length and
width as inputs.
b) tri_area() function that calculates and prints the area of a triangle taking the base and height
as inputs.
c) cir_area() function that calculates and prints the area of a circle taking the radius as input
(Hint: you may need the built-in module math).

1.2 Please code another python module called perimeter.py, which contains two functions:
a) rec_peri() function that calculates and prints the perimeter of a rectangle taking the length
and width as inputs.
c) cir_peri() function that calculates and prints the perimeters of a circle taking the radius as
input (Hint: you may need the built-in module math).

1.3 Please test the area.py module and perimeter.py module from 1.1 & 1.2 interactively, by
using import/from-import to load the exports to fetch functions to make perimeter calculations.

Question 2
2.1 Create a subdirectory called mypkg nested in a directory on your module import search path, move
the area.py module file and perimeter.py module file you created in exercises 1.1 & 1.2 into the new
directory.

2.2 Please test mypkg package by using import/from-import to load the exports and use your self-
defined functions to make area calculations.

Note: Figure 1 is an example when you import the module/package and call one of your self-
defined functions.

Figure 1 input&output example (partial)

You might also like