"reverse" exercise behaving oddly, or is it just me?


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/learn-python/lessons/practice-makes-perfect/exercises/reverse?action=lesson_resume&link_content_target=interstitial_lesson

<In what way does your code behave incorrectly? Include ALL error messages.>

Prints to the console the way I would expect it to, but this error message comes up anyway:
Your function fails on reverse(“Python!”). It returns “” when it should return “!nohtyP”.



def reverse(text):
  length = len(text)
  new_string = ""
  count = 0
  while True:
    count = count + 1
    print text[length - count], #Debug line
    new_string.join(text[length - count])
    if count == len(text):
      break
  return new_string


Here’s what the console outputs, and here’s the output on #Code, a UWP app.


#2

Error:

It returns “” when it should return “!nohtyP”

The error message simply says it returns nothing("") .you are just printing every words.comment out the following line

print text[length - count],

then you’ll know the new_string variable still contains "" what it returns.

Hint(try to solve or click here)

you have to store every joining words to new_string


#3

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