Beginner Design Recipe

# Beginner Design Recipe - the pattern How can the inputs be...

This preview shows pages 1–2. Sign up to view the full content.

BEGINNER’S DESIGN RECIPE 1. Read the problem. What kinds of data does the function consume? What kind of data does it produce? Write a short purpose statement. List all required input parameters (use meaningful names). Provide data kinds for each parameter, including the return value. Write a function that computes the area of a rectangle, given the width and height. """ +)0/+( 67897:;<= 405(+ >> 2'%?)- +)0/+( >> 2'%?)- -)('-2 >> 2'%?)- """ 2. Write the function header, using the information from the contract. 5). ,-),D405(+E +)0/+(FG HHH 3. Make up examples of inputs. What should your program produce for those inputs? Write these as unit tests using ,**)-(<I',3 . ,**)-(<I',3D,-),DJE JFE JF ,**)-(<I',3D,-),DKJE KJFE KJJF ,**)-(<I',3D,-),DKE KJFE KJF 4. Now write your function body. Look closely at your examples, and try to see

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: the pattern. How can the inputs be turned into the desired outputs? If your purpose statement indicates that different outputs should occur in different conditions, consider using an if/elif/else structure [Chapter 4]. Consider what the condition should be for each case, and what the result should be, separately. 5). ,-),D405(+E +)0/+(FG HHH-)('-2 405(+ L +)0/+( 5. Now put it all together into one Python Fle, see the next page for lab00.py .-\$% #0*#KJM 0%&\$-( L 5). ,-),D405(+E +)0/+(FG """ #\$%&'()* (+) ,-), \$. (+) /01)2 -)#(,2/3) ,* 405(+ (0%)* +)0/+( 67897:;<= 405(+ >> 2'%?)[email protected]:[email protected]= +)0/+( >> 2'%?)--)('-2 >> 2'%?)-"""-)('-2 405(+ L +)0/+( ,**)-(<I',3D,-),DJE JFE JF ,**)-(<I',3D,-),DKJE KJFE KJJF ,**)-(<I',3D,-),DKE KJFE KJF...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

Beginner Design Recipe - the pattern How can the inputs be...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online