Presentation is loading. Please wait.

Presentation is loading. Please wait.

Section 4.2: Functions that Test Conditions (continued)

Similar presentations


Presentation on theme: "Section 4.2: Functions that Test Conditions (continued)"— Presentation transcript:

1 Section 4.2: Functions that Test Conditions (continued)

2 Another Boolean-valued function ;Purpose ;To determine if someone is between 18 and 25. ;Contract ;18-to-25? : number -> boolean “Examples of 18-to-25?:” (18-to-25? 17) “should be” false (18-to-25? 48) “should be” false (18-to-25? 21) “should be” true (18-to-25? 18) “should be” true (18-to-25? 25) “should be” true

3 Another Boolean-valued function ; 18-to-25? : number -> boolean (define (18-to-25? age) … age …)) “Examples of 18-to-25?:” (18-to-25? 17) “should be” false (18-to-25? 48) “should be” false (18-to-25? 21) “should be” true (18-to-25? 18) “should be” true (18-to-25? 25) “should be” true

4 Another Boolean-valued function ; 18-to-25? : number -> boolean (define (18-to-25? age) … (>= age 18) … (<= age 25) …) “Examples of 18-to-25?:” (18-to-25? 17) “should be” false (18-to-25? 48) “should be” false (18-to-25? 21) “should be” true (18-to-25? 18) “should be” true (18-to-25? 25) “should be” true

5 Another Boolean-valued function ; 18-to-25? : number -> boolean (define (18-to-25? age) (and (>= age 18) (<= age 25))) “Examples of 18-to-25?:” (18-to-25? 17) “should be” false (18-to-25? 48) “should be” false (18-to-25? 21) “should be” true (18-to-25? 18) “should be” true (18-to-25? 25) “should be” true

6 Next time… Writing Conditional Functions


Download ppt "Section 4.2: Functions that Test Conditions (continued)"

Similar presentations


Ads by Google