2009 104

From Media Design: Networked & Lens-Based wiki
Jump to navigation Jump to search

Following up on Chapters 5 & 6 in the textbook


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))
		return False

word = raw_input("give me a word? ")
# word = "tomato"
if is_palindrome(word):
	print "hey that's a palindrome!"
	print "that's no palindrome!"


(missing file: MarkupTurtles.zip)