(*********************************************************************** Mathematica-Compatible Notebook This notebook can be used on any computer system with Mathematica 3.0, MathReader 3.0, or any compatible application. The data for the notebook starts with the line of stars above. To get the notebook into a Mathematica-compatible application, do one of the following: * Save the data starting with the line of stars above into a file with a name ending in .nb, then open the file inside the application; * Copy the data starting with the line of stars above to the clipboard, then use the Paste menu command inside the application. Data for notebooks contains only printable 7-bit ASCII and can be sent directly in email or through ftp in text mode. Newlines can be CR, LF or CRLF (Unix, Macintosh or MS-DOS style). NOTE: If you modify the data for this notebook not in a Mathematica- compatible application, you must delete the line below containing the word CacheID, otherwise Mathematica-compatible applications may try to use invalid cache data. For more information on notebooks and Mathematica-compatible applications, contact Wolfram Research: web: http://www.wolfram.com email: info@wolfram.com phone: +1-217-398-0700 (U.S.) Notebook reader applications are available free of charge from Wolfram Research. ***********************************************************************) (*CacheID: 232*) (*NotebookFileLineBreakTest NotebookFileLineBreakTest*) (*NotebookOptionsPosition[ 7608, 260]*) (*NotebookOutlinePosition[ 8693, 295]*) (* CellTagsIndexPosition[ 8649, 291]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell[TextData["15. Conditional Structures: Homework"], "Title", Evaluatable->False, AspectRatioFixed->True], Cell["Last revision: February 18 1998", "SmallText", Evaluatable->False, AspectRatioFixed->True], Cell[CellGroupData[{ Cell[TextData["Author: YourNameGoesHere"], "Subtitle", CellFrame->True, Evaluatable->False, AspectRatioFixed->True, Background->GrayLevel[0.899992]], Cell[CellGroupData[{ Cell[TextData["1. Checking Data Inside a Function"], "Subsection", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[{ StyleBox[ "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 ", Evaluatable->False, AspectRatioFixed->True], StyleBox["\"Integer Pair!\"", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier"], StyleBox[", in the second, the String ", Evaluatable->False, AspectRatioFixed->True], StyleBox["\"Element of R^3!\"", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier"], StyleBox[", and if neither, the String ", Evaluatable->False, AspectRatioFixed->True], StyleBox["\"Unknown data\"", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier"], StyleBox[ ". Do not use a multiply defined function (which has different definitions \ for different arguments), but do use a \"", Evaluatable->False, AspectRatioFixed->True], StyleBox["Switch[]", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier"], StyleBox["\" function with patterns.", Evaluatable->False, AspectRatioFixed->True] }], "Text", Evaluatable->False, AspectRatioFixed->True] }, Closed]], Cell[CellGroupData[{ Cell[TextData["2. Determining Who is in Your Class"], "Subsection", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[{ StyleBox[ "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 \"", Evaluatable->False, AspectRatioFixed->True], StyleBox["Position[]", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier"], StyleBox["\" and a conditional structure.", Evaluatable->False, AspectRatioFixed->True] }], "Text", Evaluatable->False, AspectRatioFixed->True] }, Closed]], Cell[CellGroupData[{ Cell[TextData["3. Finding Names in a Table"], "Subsection", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[{ StyleBox[ "Form a list of pairs of first and last names of individuals in a fictional \ class, such as ", Evaluatable->False, AspectRatioFixed->True], StyleBox["{{\"John\",\"Doe\"},{\"Bob\",\"Edwards\"},{\"Jane\",\"Roe\"}}", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier"], StyleBox[ ". Then write a function with one argument, using a conditional structure \ and \"", Evaluatable->False, AspectRatioFixed->True], StyleBox["Position[]", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier"], StyleBox[ "\", 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 ", Evaluatable->False, AspectRatioFixed->True], StyleBox["\"Double match!\"", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier"], StyleBox["; and if it matches no name, return ", Evaluatable->False, AspectRatioFixed->True], StyleBox["\"No match!\"", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier"], StyleBox["", Evaluatable->False, AspectRatioFixed->True] }], "Text", Evaluatable->False, AspectRatioFixed->True] }, Closed]], Cell[CellGroupData[{ Cell[TextData["4. Error Detection"], "Subsection", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[{ StyleBox[ "Using conditional structures from this section, write a function which has \ two parameters, a list ", Evaluatable->False, AspectRatioFixed->True], StyleBox["\"list\"", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier"], StyleBox[" and an integer ", Evaluatable->False, AspectRatioFixed->True], StyleBox["\"n\"", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier"], StyleBox[", and returns ", Evaluatable->False, AspectRatioFixed->True], StyleBox["\"list\"", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier"], StyleBox[" with the first ", Evaluatable->False, AspectRatioFixed->True], StyleBox["\"n\"", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier"], StyleBox[" elements dropped, unless ", Evaluatable->False, AspectRatioFixed->True], StyleBox["\"n\"", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier"], StyleBox[" is zero or negative or not an integer, or ", Evaluatable->False, AspectRatioFixed->True], StyleBox["\"list\"", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier"], StyleBox[" is not a list, in which case the function returns the string ", Evaluatable->False, AspectRatioFixed->True], StyleBox["\"Invalid input\"", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier"], StyleBox[".", Evaluatable->False, AspectRatioFixed->True] }], "Text", Evaluatable->False, AspectRatioFixed->True] }, Closed]] }, Open ]] }, Open ]] }, FrontEndVersion->"Macintosh 3.0", ScreenRectangle->{{0, 832}, {0, 604}}, WindowToolbars->{}, WindowSize->{520, 509}, WindowMargins->{{68, Automatic}, {30, Automatic}}, PrintingCopies->1, PrintingPageRange->{1, Automatic}, PrivateNotebookOptions->{"ColorPalette"->{RGBColor, -1}}, ShowCellLabel->True, ShowCellTags->False, RenderingOptions->{"ObjectDithering"->True, "RasterDithering"->False}, MacintoshSystemPageSetup->"\<\ 00<0004/0B`000003809T?o>old" ] (*********************************************************************** Cached data follows. If you edit this Notebook file directly, not using Mathematica, you must remove the line containing CacheID at the top of the file. The cache data will then be recreated when you save this file from within Mathematica. ***********************************************************************) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[1731, 51, 113, 2, 136, "Title", Evaluatable->False], Cell[1847, 55, 101, 2, 26, "SmallText", Evaluatable->False], Cell[CellGroupData[{ Cell[1973, 61, 156, 4, 78, "Subtitle", Evaluatable->False], Cell[CellGroupData[{ Cell[2154, 69, 114, 2, 46, "Subsection", Evaluatable->False], Cell[2271, 73, 1226, 39, 97, "Text", Evaluatable->False] }, Closed]], Cell[CellGroupData[{ Cell[3534, 117, 115, 2, 30, "Subsection", Evaluatable->False], Cell[3652, 121, 610, 17, 63, "Text", Evaluatable->False] }, Closed]], Cell[CellGroupData[{ Cell[4299, 143, 107, 2, 30, "Subsection", Evaluatable->False], Cell[4409, 147, 1401, 42, 131, "Text", Evaluatable->False] }, Closed]], Cell[CellGroupData[{ Cell[5847, 194, 98, 2, 30, "Subsection", Evaluatable->False], Cell[5948, 198, 1620, 57, 81, "Text", Evaluatable->False] }, Closed]] }, Open ]] }, Open ]] } ] *) (*********************************************************************** End of Mathematica Notebook file. ***********************************************************************)