Why the code that reverses the string fails?

The code is to reverse the string, but it fails. I can’t find out the problem. Can somebody help me?

def reverse(text): string = '' for i in range(:len(text)): string = string + text[len(text)-i-1] return string print(reverse('ytrdtrd'))

I’m sorry for the format if there’s something wrong.

Double check your syntax as it points out in the error message.

Sometimes the messages aren’t so clear as to where the issue is, but this one points directly where in your code there’s an issue.

Also, fwiw, if you read your code from the bottom up, it makes you see it/interpret it differently and you might have an easier time finding bugs.

Happy coding!


Thanks so much for your reply. You provide a new way for me: check my code from the bottom. I’ll try. Thanks again!

1 Like

I don’t know why the staff removed my answer. I’ve solved this problem. The code went wrong because the colone in line 3, in the parentheses after range. It shouldn’t exist. The right syntax or form is:
for i in range(len(text)):