CMPT 120 Lecture 21: Part 3: Functions

12 views2 pages
meghan78 and 39786 others unlocked
CMPT 120 Full Course Notes
29
CMPT 120 Full Course Notes
Verified Note
29 documents

Document Summary

Modularization: grouping of related functions in modules (python files) for better organization. Makes program easier to understand, test, and maintain. Make it easier to reuse code for multiple different programs. We import the required modules in the program. Module is a file that contains python code. Contains function definition but does not contain calls to the functions. Cannot be the same as a python keyword. # the area function accepts a circle"s radius as an. # argument and returns the area of the circle. def area(radius): return math. pi * radius**2. # radius and returns the circle"s circumference. def circumference(radius): return 2 * math. pi * radius. # the rectangle module has functions that perform. # the area function accepts a rectangle"s width and. # length as arguments and returns the rectangle"s area. def area(width, length): return width * length. # the perimeter function accepts a rectangle"s width. # and length as arguments and returns the.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents