Calculate anything

Page 13

The turtle is great at arithmetic. Much better than you and me. Do you want to know what 465 + 223 is? Just tell the turtle:

print 465 + 223

He will tell you. The turtle can calculate anything fast as lightning. Let's try some really large numbers:

print 356567 * 992321

Now let's calculate something interesting. How many seconds are there in a year? There are 60 seconds in one minute. There are 60 minutes in one hour. There are 24 hours in a day. There are 365 days in a year. Therefore there are 60 * 60 * 24 * 365 seconds in a year. How much is that? Ask Logo:

print 60 * 60 * 24 * 365

He can also divide and subtract:

print 4809 - 123 ; this is subtraction
print 3457890 / 345 ; this is division

The turtle can calculate many things at the same time. Like this:

print 4 * 2 + 3 - 6

Use ( ) if you want him to calculate one thing before another. Like this:

print 3 + 4 * 2 ; this is 11
print (3 + 4) * 2 ; this is 14

Why is 3 + 4 * 2 = 11? Because the turtle likes multiplication better. He always does that first. So first he calculates 4 * 2 = 8. Then he calculates 3 + 8 = 11.

Why is (3 + 4) * 2 = 14 then? Because when we use ( ) the turtle will always calculate what's there first. So he starts with 3 + 4 = 7. Then he calculates 7 * 2 = 14.

Now type these in:

print 100 + 100
print [100 + 100]

Do you understand the difference? The difference is that with [ ] the turtle will say exactly what we tell him to. If we don't use [ ] he will calculate first.

The turtle can calculate things whenever you want him to. That means that these three lines mean the same thing:

REPEAT 4 [FD 100 RT 90]
REPEAT 4 [FD 50 * 2 RT 90]
REPEAT 2 + 2 [FD 25 * 4 RT (44 + 1) * 2]

These are the Logo words we know now:

Logo word What it means
FD 100 Walk forward 100 steps
BK 100 Walk backward 100 steps
LT 90 Turn left (good for drawing squares)
RT 90 Turn right (good for drawing squares)
LT 120 Turn left (good for drawing triangles)
RT 120 Turn right (good for drawing triangles)
CS Remove everything you have drawn
HOME Move back to the starting point (and draw a line)
PU Lift the pen so you won't draw when you walk
PD Put the pen towards the screen again
REPEAT 10 [       ] Repeat what's in the box 10 times
SETPC 4 Change the pen to pen number 4
TO ... END Remember the word after TO in the future
; Don't listen to me now
PRINT [I'm a turtle!] Say "I'm a turtle!"
RANDOM 10 Choose a number from 0 to 9
WAIT 60 Wait for 1 second.
PRINT 2+2 Makes the turtle say 4

These are the words we have taught the turtle. They are the same as on the last page:

New Logo word What it means
SQUARE Draw a square
CIRCLE Draw a circle
STAR Draw a star

Turn page, or go back to the table of contents.