COP 3223H meeting -*- Outline -*- * Predicate functions ** definition ------------------------------------------ PREDICATES def: a *predicate* is a function that ------------------------------------------ ... returns a Boolean value Predicates are useful for abstracting conditions ** examples ------------------------------------------ EXAMPLE PREDICATES def odd(n): """Return True just when n is an odd number.""" ------------------------------------------ ... return n % 2 == 1 Q: How would you define the predicate "even"? ------------------------------------------ FOR YOU TO DO Write a predicate, positive(n), that returns True just when n is a positive number. ------------------------------------------ ... def positive(n): """Is n greater than zero?""" return n > 0 ------------------------------------------ FOR YOU TO DO Write a predicate, strictly_ascending(n1, n2, n3) that returns True just when n1 < n2 and n2 < n3. ------------------------------------------ ... def strictly_ascending(n1, n2, n3) """Return True just when n1 < n2 and n2 < n3""" return n1 < n2 and n2 < n3