can any one help me to solve this program?


You can't use a function name as a variable. Right now, you have a function called reverse AND a variable reverse = []. You can't do that as python is thinking you're trying to assign empty list, [] to your function call.


i tried by taking out empty list but program shows me that i have problem in line 6
ie (len(text) -= 1) can one help me? whey it went wrong.

Thank you


Now I see what you're trying to do. You're trying to figure out how to start the loop with the last letter and append the last letter to the new list (and keep on going).
The reason why len(text)-=1 is not working is because you're changing the range of the loop (which is not a good idea).

Some suggestions:
1. Rename your empty list/new list variable to anything other than reverse and text.
eg. result = []
2. Upon further research from Google on how to loop through elements in the text backwards, you can do
range(len(text) - 1, -1, -1) len(text)-1is where to start, -1 is where to end (remember it's not inclusive so it stops at 0 putting 0 instead of -1 will make it stop at 1) and the last is the decrement of the index. This is NOT encouraged because it wastes memory space in Python. But you don't need thelen(text) -= 1 anymore.
There are other methods!!
3. Make sure to return your function and use ''.join() so it comes out as strings and not list of strings.


This is my code i had changed it as u instructed. could you inform me where i went wrong?


you are still using function name "reverse" as your list variable.try changing you 5th and 8th lines of code


Building from what @gksahiti has mentioned:
You didn't return either. Instead, you printed. (Also check indentation of your code).
range(len(text) - 1, -1, -1) should replace the range(len(text),0) in your for loop statement.


which argument i have to give in join statement?


Your text isn't a list. You can't append to something that isn't a list. Isn't your result a list? Why not append text[i] to that?

Buddy, remember to return.
return ''.join(insert your list).
You list is results, correct? Put that in the join().


This is how i got code. I did't understand it? my append statement was correct.could any one help me to solve it?


No, you're not appending it correct. Your text is just a string. You cannot append to a string but a list. Why not do result.append(text[i])?

Please replace print with return as well.


Thank you for helping me to solve this program. I really thank for your patience


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