Reverse


#1

I can’t figure out what’s wrong with my code; here are the error messages:

Your function fails on reverse(“Python!”). It returns “[‘P’, ‘!’, ‘n’, ‘o’, ‘h’, ‘t’, ‘y’, ‘P’]” when it should return “!nohtyP”.

It seems to work except for the first letter. I think it is a problem with my range() function parameters.

Here is my code:

def reverse(text):
  new_word = []
  for i in range(len(text)+1):
    new_word.append(text[-i])
  return new_word

#2

That could be your problem.

Recall that the last element is at index [-1]. Try starting your range on 1.


#3

you’re also returning an array instead of a string


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.