Beginner Design Recipe

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

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

View Full Document Right Arrow Icon
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'%?)- 6@:AB9C@B= +)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
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
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%&amp;$-( L 5). ,-),D405(+E +)0/+(FG &quot;&quot;&quot; #$%&amp;'()* (+) ,-), $. (+) /01)2 -)#(,2/3) ,* 405(+ (0%)* +)0/+( 67897:;&lt;= 405(+ &gt;&gt; 2'%?)-6@:AB9C@B= +)0/+( &gt;&gt; 2'%?)--)('-2 &gt;&gt; 2'%?)-&quot;&quot;&quot;-)('-2 405(+ L +)0/+( ,**)-(&lt;I',3D,-),DJE JFE JF ,**)-(&lt;I',3D,-),DKJE KJFE KJJF ,**)-(&lt;I',3D,-),DKE KJFE KJF...
View Full Document

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 Right Arrow Icon
Ask a homework question - tutors are online