2009 104: Difference between revisions
(New page: * http://wikipedia.org/wiki/Koch_snowflake) |
|||
(11 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
Following up on Chapters 5 & 6 in the [[Think Python | 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! | |||
[http://norvig.com/palindrome.html about this palindrome] | |||
[http://www.spinelessbooks.com/2002/ a palindromic story] | |||
One solution: | |||
<source lang="python"> | |||
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!" | |||
</source> | |||
= Afternoon = | |||
(missing file: MarkupTurtles.zip) | |||
* [[wikipedia:Koch snowflake]] |
Latest revision as of 22:58, 23 September 2010
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!
about this palindrome a palindromic story
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!"
Afternoon
(missing file: MarkupTurtles.zip)