Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due
CSC108 Recipe for Designing Functions
1. Examples Pick a name for the function (often a verb or verb phrase). Sometimes a good name is a short answer to the question “What does your function do?”
Write one or two examples of calls to your function and the expected returned values. Include an example of a standard case (as opposed to a tricky or corner case). Put the examples inside a triple-quoted string that you’ve indented since it will be the beginning of the docstring.
2. Header Write the function header above the docstring and outdent it. Choose a meaningful name for each parameter (often nouns). Include the type contract (the types of the parameters and return value).
3. Description Before the examples, add a description of what the function does and mention each parameter by name. Describe the return value.
4. Body Write the body of the function and indent it to match the docstring. To help yourself write the body, review your example cases from step 1 and consider how you determined the return values. You may find it helpful to write a few more example calls.
5. Test Your Function Test your function on all your example cases including any additional cases you created in step 4. Additionally, try it on extra tricky or corner cases.
Another Example Write a function that accepts the number of pizzas that you are ordering and the number of slices per pizza, and returns the total number of slices in the order.
1. Examples
2. Header
3. Description
4. Body
5. Test Call your function and compare the return values to what you are expecting.