Reverse - almost but not quite


I've managed to come up with code that does the work but not quite as expected. Any suggestions as to how to fix it will be most welcome

wrd = raw_input("Enter a word: ")
def reverse(wrd):
    x = len(wrd) # determine the lenght of the string
    for i in str(wrd):
        print wrd[x - 1], # print the index position x-1 in every loop
        x -= 1 # diminish x by 1 with every loop
reverse(wrd) # for raw-input Python prints n o h t y PNone


Problem: your function needs to return the reversed string. You currently print the reversed string

You are pretty close to printing the reversed string, you need a little more work to make your function capable of returning the reversed string


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