15.  Conditional Structures:  Homework

Last revision:  February 18 1998

Author: YourNameGoesHere

1. Checking Data Inside a Function

Write a function which determines whether its argument is a list of two integers or a list of three real numbers; in the first case, it should return the String "Integer Pair!", in the second, the String "Element of R^3!", and if neither, the String "Unknown data".  Do not use a multiply defined function (which has different definitions for different arguments), but do use a "Switch[]" function with patterns.

2. Determining Who is in Your Class

Create a list of names in a class, fictional or otherwise, and then define a function which tests whether or not a person is in the class, returning his or her position in the list if the person is in the class, and a message if the person is not.  Use "Position[]" and a conditional structure.

3. Finding Names in a Table

Form a list of pairs of first and last names of individuals in a fictional class, such as {{"John","Doe"},{"Bob","Edwards"},{"Jane","Roe"}}.  Then write a function with one argument, using a conditional structure and "Position[]", which determines if the argument matches a first or last name in the list.  If it matches a first name, return the corresponding last name; if it matches a last name, return the corresponding first name; if it matches a first name of one pair and a last name of a pair, return "Double match!"; and if it matches no name, return "No match!"

4. Error Detection

Using conditional structures from this section, write a function which has two parameters, a list "list" and an integer "n", and returns "list" with the first "n" elements dropped, unless "n" is zero or negative or not an integer, or "list" is not a list, in which case the function returns the string "Invalid input".