Reverse


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/1?curriculum_id=4f89dab3d788890003000096


I am not sure if I am close, or WAY off. I get:
!
!n
!no
!noh
!noht
!nohty
!nohtyP
None
and this error message.
Oops, try again. Your function fails on reverse("Python!"). It returns "None" when it should return "!nohtyP".

Thanks for any help you can offer.

def reverse(text):
    word = ""
    i = len(text) -1
    for c in text:
       word = (text[i])
       i -= 1
       print word
      
        
reverse("Python!")


#2

I suggest you move the print statement outside the loop (lined up with the for loop) to just get !nohtyP. Also you are not returning anything but instead, you are printing.
You can put return word after print word to return. Or just return word and print reverse("Python!") to print onto console.


#3

I can't believe I was that close. Thank you!


#4

def reverse(text):
p = len(text) - 1
i = 0
for text[i] in text:
text[i] = p
i += 1
p -= 1
word = text[i]
print word

reverse(python)

getting error...:expressionless:


#5

def reverse(text):
p = len(text) - 1
i = 0
for text[i] in text:
text[i] = text[p]
word = text[i]
i += 1
p -= 1
return word

reverse(python)

help meeee


#6

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