DOC PREVIEW
CSUDH TBE 540 - Logo Lesson 5

This preview shows page 1-2-3-20-21-22-41-42-43 out of 43 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Logo Lesson 5PrerequisitesObjectivesLogo ListsSlide 5Slide 6Slide 7Sentences in LogoSlide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18Slide 19An Addition DrillSlide 21Slide 22Slide 23Slide 24Slide 25Slide 26An Additional DrillSlide 28Slide 29Slide 30As Addition DrillRecursionSelf Check Lesson 5Slide 34Slide 35Slide 36Slide 37Slide 38Slide 39Slide 40Slide 41Slide 42Slide 43Logo Lesson 5TBE 540-40Fall 2004Farah FisherPrerequisitesGiven a shape, use basic Logo commands and/or a procedure to draw the shape, with and without the use of variables.Use SAVE, LOAD and POTS to manage Logo workspaces.Demonstrate the use of RANDOM.ObjectivesPut a list of words into a variable and print any item of the list.Print a sentence in Logo, with and without variables.Print a sentence in Logo from randomly chosen words.Demonstrate use of IF and IFELSE.Create a Logo procedure that demonstrates the use of recursion.Logo ListsA list in Logo a set of values all stored under the same variable name.Other programming languages call this an array.Each value stored in the list is called an item.Each item has a number, e.g., in the list [HOT COLD DOG], item #3 is DOG.Logo ListsHere is a sample of the creation of a list within a procedure:•MAKE “COLORS [RED GREEN BLUE]If you (print) PR :COLORS, all three colors will appear.If you PR ITEM 2 :COLORS the word GREEN will appear.Logo ListsPR ITEM 1 + RANDOM 3 :COLORS will display a randomly chosen word from the list of three.Lists are very useful in choosing words at random. MAKE “WORD1 ITEM 1 + RANDOM 3 :COLORS would put a randomly chosen word from the list into the variable :WORD1Logo ListsLogo lists may also contain numbers. Here is a list of prime numbers put into a variable called PRIME.•MAKE “PRIME [1 2 3 5 7 11 13 17 19 23]What would appear if you typed this? PR ITEM 6 :PRIME (11 would be printed, since it is the 6th item)How would you choose at random from the list? A possible command:•MAKE “F ITEM 1 + RANDOM 10 :PRIMESentences in LogoYou have seen several examples of the PR (print) command. It can be used to display the value of variables or messages.Next you will see how to put several pieces of information together in a “sentence.”Sentences in LogoIf you already know all the words in a sentence, you can simply put it inside brackets, like PR [HERE IT IS.]But what if you are trying to include variables (words or numbers)?For example, suppose you asked someone to enter his/her name, and you want to print HI and the name he/she entered.Sentences in LogoThe commands to ask for and get the name would be•PR [PLEASE TYPE YOUR NAME.]•MAKE “NM READLISTIf you typed PR [HI :NM] to print, you would not get the result you want. PR [HI :NM] would actually display HI :NM (rather than the actual name), since information in [ ] is taken literally.Sentences in LogoTake a look at the third line of commands:•PR [PLEASE TYPE YOUR NAME.]•MAKE “NM READLIST•PR (SE [HI,] :NM)The SE means SENTENCE (“print as a sentence, with spaces between the parts”). Notice the use of ( ) instead of [ ] . The [HI,] is taken literally, but the :NM prints whatever is input in the previous line.Sentences in LogoExamine the following procedure:•TO EXCHANGE•PR [PLEASE TYPE YOUR NAME.]•MAKE “NM READLIST•PR (SE [HI,] :NM)•ENDRunning the procedure:•EXCHANGE (to start the procedure)•PLEASE TYPE YOUR NAME.•MARY SMITH (entered by the user)•HI, MARY SMITHSentences in LogoNext we are going to create a procedure that puts together sentences from randomly chosen words.This procedure will (1) create lists of words (verbs, nouns, adjectives), (2) choose randomly from these lists, and (3) put the randomly chosen words into a sentence and print it.Sentences in LogoWe will use a sentence format like this:•THE adjective noun verb.•Example: THE HAPPY DOG RUNS.To make lists of words:•MAKE “VERBS [RUNS HOPS SINGS]•MAKE “NOUNS [DOG TREE CAR]•MAKE “ADJ [HAPPY GREEN BIG]Sentences in LogoTo choose randomly from these lists:• MAKE “WORD1 ITEM 1 + RANDOM 3 :ADJ •MAKE “WORD2 ITEM 1 + RANDOM 3 :NOUNS•MAKE “WORD3 ITEM 1 + RANDOM 3 :VERBSSentences in LogoThe procedure thus far…•TO RANDOM.SENTENCE•MAKE “VERBS [RUNS HOPS SINGS]•MAKE “NOUNS [DOG TREE CAR]•MAKE “ADJ [HAPPY GREEN BIG]•MAKE “WORD1 ITEM 1 + RANDOM 3 :ADJ •MAKE “WORD2 ITEM 1 + RANDOM 3 :NOUNS•MAKE “WORD3 ITEM 1 + RANDOM 3 :VERBSSentences in LogoTo put the words into a sentence, we will use PR (print) and SE (sentence).Remember that we are trying for•THE adjective noun verb.Here is the Logo printing command we will use: PR (SE [THE] :WORD1 :WORD2 :WORD3 [.])Sentences in LogoThe final version:•TO RANDOM.SENTENCE•MAKE “VERBS [RUNS HOPS SINGS]•MAKE “NOUNS [DOG TREE CAR]•MAKE “ADJ [HAPPY GREEN BIG]•MAKE “WORD1 ITEM 1 + RANDOM 3 :ADJ •MAKE “WORD2 ITEM 1 + RANDOM 3 :NOUNS•MAKE “WORD3 ITEM 1 + RANDOM 3 :VERBS•PR (SE [THE] :WORD1 :WORD2 :WORD3 [.])•ENDSentences in LogoHow could you make RANDOM.SENTENCE into a “random story”?How about…•TO RANDOM.STORY•REPEAT 5 [RANDOM.SENTENCE]•ENDAn Addition DrillLogo sentences can be constructed using numbers, too.Suppose you are trying to make an addition drill with random problems.You would have to create a procedure that (1) chooses two random numbers, (2) displays the addition problem, (3) gets the answer, (4) checks to see if it is correct, and (5) gives feedback.An Addition DrillChoosing two random numbers would look like this:•MAKE “X 1 + RANDOM 10•MAKE “Y 1 + RANDOM 10To print the problem as a sentence:•PR (SE :X [+] :Y [= ?])What would be different for a multiplication problem? For larger numbers?An Addition DrillGetting the answer would look like this:•MAKE “ANS FIRST READLISTThe procedure so far is…•TO ADD. PROBLEM•MAKE “X 1 + RANDOM 10•MAKE “Y 1 + RANDOM 10•PR (SE :X [+] :Y [= ?])•MAKE “ANS FIRST READLISTAn Addition DrillThe next step is to check the answer.The question is…how will the computer know the right answer when two random numbers were chosen?The correct answer should be :X + :Y since :X and :Y contain the chosen numbers.But how will the computer compare the student’s answer with the


View Full Document

CSUDH TBE 540 - Logo Lesson 5

Download Logo Lesson 5
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Logo Lesson 5 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Logo Lesson 5 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?