FAQ: Recursion vs. Iteration - Coding Throwdown - Taco Cat


This community-built FAQ covers the “Taco Cat” exercise from the lesson “Recursion vs. Iteration - Coding Throwdown”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Recursion: Python

FAQs on the exercise Taco Cat

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

I found a bug in this lesson.

Whenever I run the code I wrote, it tells me I pass, and I did, but it shows the last print call to be True when it is actually False. Even the print calls I use to compare the two characters show they are DIFFERENT, it still evaluates to True when I compare them.

def is_palindrome(word):
  if len(word) < 2:
    return True
  if word[0] != word[-1]:
      return False
  return is_palindrome(word[1:-1])

# test cases
print(is_palindrome("abba") == True) 
print(is_palindrome("gmcmg") == True)
print(is_palindrome("") == True)
print(is_palindrome("abcd") == False) # Prints True when it is False.

Ah, it’s checking if “abcd” == False if “abcd” == False then this is True. You want all Trues because it means that your code works when it is supposed to and catches the False when it is suppose to.

It’s checking if your function produces a False when “abcd” is passed in. If it does this will print True. If “abcd” produces a True then “abcd” does not == False and it would say False and your code is not doing something it’s supposed to.

:upside_down_face: Hope this made some sense.


Soon as I read your first 7 words, it hit me! I was thinking, for some idiotic reason, that the == False areas of the statements were showing me what it SHOULD be.

Thanks for slapping me in the face and waking me up! I swear, coding for 13 hours makes you get loopy and miss things. Thanks you!


Does the below solution is a good approach recursively? I just wrote it, it did pass all the cases but, I am doubtful… It was not same as the hint given.

def is_palindrome(my_string):
if len(my_string) > 1:
if my_string[0] != my_string[-1]:
return False
return is_palindrome(my_string[1:-1])
return True

1 Like

Judging by how long this course has been around we’ve likely seen this same solution N number of times. Is there really a question, here, or are we free to go?

1 Like

I have it done like this. It runs successfully and gives the required result.
My question is, what goes wrong in the code if I do not have return in the elif statement. Why is return a must there?

def is_palindrome(my_string): 
  if len(my_string)== 1 or len(my_string)==0: 
    return True 
  elif my_string[0]== my_string[-1]:  
    return(is_palindrome(my_string[1: -1]))
    return False 
# test cases
print(is_palindrome("abba") == True)
print(is_palindrome("abcba") == True)
print(is_palindrome("") == True)
print(is_palindrome("abcd") == False)

Because it is necessary in building the call stack. When the string is consumed (whittled down to nothing) the base case is reached and the call stack winds down.