What is wrong with my code?


#1



def reverse(text):
    m=-1
    for i in text:
        p=text[i]
        m+=1
    while m>=0:
        return text[m]
        m=m-1


#2

why you use while ?? and you should return p , also what the purpose of using varaible m ?


#3

Thank you, the first for loop is about counting the length of string which m gives this length. I used the while to made a condition to enumerate from the last character for returning.


#4

you can use len() to count the length of a string , and your code for counting is correct ,
variable i is string not integer so is not correct to use i in text[i] , and i didn't see the purpose of p=text[i] .
while will loop but will return one letter


#5
@muhammadzerehizadeh While loop was a good choice to solve this 
def reverse(text):
    x, new = str(text), ""
    c = len(x)
    while c > 0:
	    c -= 1
	    new = new + x[c]
    return new