why does putting letters in line 5 work but when i put len(text) it doesnt? arent they basically the same thing?

def reverse(text):
    rev = ""
    letters = len(text)
    while letters > 0:
        rev += text[ letters -1 ]
        letters -= 1
    return rev
Replace this line with your code.


because you decrease the value in letters:

letters -= 1

which means you go from high to lower index of text, while len(text) will stay the same length


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