I passed this section but still I am confused, CAN ANYONE EXPLAIN ME PLEASE.
Suppose the text is " PYTHON"
In my code if I put this [for i in range (n, -1, -1) ]. It shows error. I did this because nth item is "N" so the new word will start from "N". Why is this incorrect?
But, in my code [ for i in range (n-1, -1, -1) ]. It means that counting starts from n-1 and ends at -1. The (n-1)th item in the word Python is "O", that means it should start from "O". I think this code should print "OHTYP" but it says correct. How is this correct???
Am I missing something. please help.
Can anyone please explain me this? Thanks in advance.
def reverse(text): n = len(text) x = "" for i in range(n-1, -1, -1): x = x + text[i] return x