2009 104: Difference between revisions
Line 43: | Line 43: | ||
= Afternoon = | = Afternoon = | ||
[ | [[Media:MarkupTurtles.zip]] | ||
* http://wikipedia.org/wiki/Koch_snowflake | * http://wikipedia.org/wiki/Koch_snowflake |
Revision as of 14:52, 4 November 2008
Following up on Chapters 5 & 6 in the textbook
Morning
Review of the palindrome problem
steve suggests:
A man, a plan, a canoe, pasta, heros' rajahs, a coloratura, maps, snipe, percale, macaroni, a gag, a banana bag, a tan, a tag, a banana bag again (or a camel), a crepe, pins, Spam, a rut, a Rolo, cash, a jar, sore hats, a peon, a canal - Panama!
One solution:
def first(word):
return word[0]
def last(word):
return word[-1]
def middle(word):
return word[1:-1]
def is_palindrome (word):
print "is_palindrome(" + word + ")"
if word == "":
return True
if first(word) == last(word):
return is_palindrome(middle(word))
else:
return False
word = raw_input("give me a word? ")
# word = "tomato"
if is_palindrome(word):
print "hey that's a palindrome!"
else:
print "that's no palindrome!"