Is this program correct?


#1

def reverse(text):
word=""
l = len(text) - 1
for x in range(l,-1):
word = word + text[x]
return word
print reverse(“abcd”)

is this program correct for doing a reverse for a string


#2

Our question back to you is, “Does it work?” If not, then there is your answer.

To reverse a range, we make the start value the highest index, the end value one less than zero (recall that range excludes the final value) and the stride negative one.

range(len(text) - 1, -1, -1)

#3

thank you sir , ya now i understand it we need to stride back