for i in range(4):
t.forward(100)
t.left(90)
what does the range(4) do?
range(4) generates numbers, from 0 to 3
if you ask Python to print range(4) in IDLE, what do you get?
Notice the square brackets? They are important!
They indicate something really important in Python: a LIST
We can use range() to print sequential numbers:
for i in range(4):
print i
Remember that range(4) prints out [0,1,2,3]?
We could code our for loop this way:
for i in [0,1,2,3]:
print i
But why do the work when the computer is better at it?
Let's forget our turtle for a moment and let's throw a party!
We want to invite a few friends to our Saturday party but we want each invitation to be personalized
Let's make a list of our guests
guests = ["Lea", "Ben","Isabelle","Michael"]
guests will be our variable
The list starts with the square bracket
Commas separate each item of our list
Our guest names are strings, so they will need quotes
the list ends with the closing square bracket
for g in guests:
print "Hello "+g+"! You are invited to my party!"
Let's ask them to bring some food
food=["chips","hotdogs","soft drinks","carrots"]
as long as the list of foods is the same length as the list of guests, we'll be fine
Now we have a lot of power at our fingertips!
Notice the new stamp() method
Getting DIZZY!!!