COP 3223H meeting -*- Outline -*- * Friday Problems with Boolean Expressions and Predicates ** truth tables ------------------------------------------ TRUTH TABLES FOR AND, OR AND arg1\arg2 | True | False True | True | False False | False | False OR arg1\arg2 | True | False True | True | True False | True | False ------------------------------------------ ------------------------------------------ FOR YOU TO DO 1. Write a Python procedure print_truth_tables() that prompts to stdout and reads from stdin. When called, it asks "Which table? " and then reads in the string "and" or "or" (without the quotes). Then it prints the truth table (on stdout) for the operator requested. For example, an interaction might be: Which table? and arg1\arg2 | True | False True | True | False False | False | False The other example is: Which table? or arg1\arg2 | True | False True | True | True False | True | False ------------------------------------------ ** a pure predicate ------------------------------------------ FOR YOU TO DO 2. Write a function, divisible(n,d), that takes two positive integers, n, and d, and returns True just when n is divisible by d (i.e., when n % d == 0). Some true assertions about divisible: divisible(4,2) divisible(9,3) divisible(7,7) divisible(49,7) but note: not divisible(5,2) not divisible(7,3) not divisible(12,5) ------------------------------------------ ** interaction and conditionals ------------------------------------------ FOR YOU TO DO 3. Write a procedure, name_polygon(), that prompts for a positive integer, on stdout, with the prompt "number? ", and reads an int, n > 2, from stdin, and then prints out the English name for a regular polygon with n sides (on stdout). Some example interactions: number? 3 triangle number? 4 square number? 5 pentagon number? 6 hexagon number? 8 octagon number? 27 27-gon ------------------------------------------ ** predicate ------------------------------------------ FOR YOU TO DO 4. Write a predicate, descending_digits(n), that takes an integer n, where 10 <= n <= 99, and returns True just when the digits of n are in strictly descending order. For example the following assertions are true about this predicate: descending_digits(32) descending_digits(51) descending_digits(98) descending_digits(10) but note: not descending_digits(99) not descending_digits(15) not descending_digits(39) ------------------------------------------