Reverse() function, why system does not let me go~


#1

The following is my code (without "##"):

def reverse(x):

new_string=[]

count=0

while count<len(x):

new_index=len(x)-count-1

new_string.append(x[new_index])

count+=1

print "".join(new_string)

reverse("safg@e")

reverse("Python!")

I can print the right string successfully, but why it doesn't let me pass~!?


#2

Hi, make sure that you're describing the situation well enough so that others can understand and reproduce what's going on.

You mention printing, but is that what the instructions tell you to do? If it's asking for something else then it doesn't matter what you're printing


#3

def reverse(x):
new_string=[]
count=0
while count<len(x):
new_index=len(x)-count-1
new_string.append(x[new_index])
count+=1
return ''.join(new_string)
you were not using return statement buddy


#4

Thank you very much. I just changed the print into return and it works.


#5

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