Download presentation
Presentation is loading. Please wait.
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
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.