def first(word): return word[0] def last(word): return word[-1] def middle(word): return word[1:-1] def is_palindrome(word): print("entering is_palindrome('" + word + "')") if len(word) == 1 or (len(word) == 2 and word[0] == word[1]): print("returning True from is_palindrome('" + word + "')\n") return True elif first(word) == last(word): word=word[1:-1] childresult = is_palindrome(word) print("is_palindrome('" + word + "') returned " + str(childresult) + "\n") # Now try commenting out the following line by prefixing it with a pound/hash symbol # Run again and see what happens. return childresult else: print("returning False from is_palindrome('" + word + "')\n") return False w = raw_input() print("outermost call returns " + str(is_palindrome(w)))
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question