Reverse Function


What I tried to do for this function is first create a function which takes text, turns it into a string and puts it in a list in reverse order. Then I created another function which would simply print this list as a string. I tried to see what was wrong and I just can't figure it out; I keep getting the error "Traceback (most recent call last):
File "python", line 10, in
File "python", line 8, in reverse
File "python", line 5, in turn_to_list
TypeError: cannot concatenate 'str' and 'int' objects"

The error seems to be as a result of the text not being properly being into a string but I tried to convert a into the argument "a" into a string in the turn_to_list function so I can't see what I'm doing wrong.

My code:

def turn_to_list(a):
  b = []
  for i in range(0, len(a) + 1):
      b.append(a[len((a + 1) - i)])
def reverse(text):
  print "".join(turn_to_list(text))



(a + 1)

a is a string, 1 is a integer, this doesn't go together. Maybe you should get the length of a first before adding 1 and subtracting i?


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