Presentation is loading. Please wait.

Presentation is loading. Please wait.

Documenting a function. Documenting a function definition We have a template for information that we need you to put at the top of each function - if.

Similar presentations


Presentation on theme: "Documenting a function. Documenting a function definition We have a template for information that we need you to put at the top of each function - if."— Presentation transcript:

1 Documenting a function

2 Documenting a function definition We have a template for information that we need you to put at the top of each function - if you do this as part of your design, you will be ready when you write the implementation The name of the function The purpose of the function The preconditions = the parameters – their meaning, not just their number! The postconditions = the return value and/or output The design

3 Example: ‘’’ function draw_circle purpose: draws the circle specified on the graphics window, using the Zelle graphics library preconditions: x and y of center of circle, radius of circle, color of line to draw with, and graphwin object to display circle on postconditions: nothing returned, circle as specified drawn on given window Design 1.Create circle object with point and radius provided 2.Set the color of the circle to given color 3.Draw the circle ‘’’

4 A docstring Some people and software companies have a standard requirement of putting all this information in a triply-quoted string at the very top of the function. It’s called a “docstring” in that case Some software that professionals use can actually pull out those comments to produce documentation for their company In this class it’s up to you whether you use the ‘’’ or the # to make these comments Of course, you put your implementation between the lines of design comments, as usual, when writing the Python code


Download ppt "Documenting a function. Documenting a function definition We have a template for information that we need you to put at the top of each function - if."

Similar presentations


Ads by Google