Python 2 / loops / Reverse. Please help!

Course : Learn Python 2 / 8_Loops / PRACTICE MAKES PERFECT / 7_Reverse


I’m totally new to coding and therefore in Python language.

I’m blocking on this exercise asking to reverse the letters of a word through a loop.
Ex : reverse (hello) # return “olleh”

I found some answers on this topic in the forum but it seems that it does not work.
So here I submit my code to ask for your help:

def reverse (text):
    rev =""
    i = len(text)-1
    while i >= 0:
        rev += text[i]
        i -= 1
    return rev

when I call reverse function, here is the answer :

 " Traceback (most recent call last):
   File "python", line 9, in <module>
   NameError: name 'hello' is not defined"

I thank you in advance for your answers and your indulgence. :légèrement_message:

Hey @system0294051300!

Did you remember to put quotes around hello?

Well, that was it !!!
I was stuck for hours. It will teach me to be more vigilant.
Thank you for your help.

1 Like