7/15 Help please! What can I be doing different?


Here’s my code:
def reverse(text):
last = (len(text) - 1)
while last >= 0:
print text[last],
last -= 1


And here is the output:


Where is the ‘cba’ coming from?

Thanks for any help!


its very likely caused by the exercise validation, what if you include multiple function calls at the end of your script:

print reverse("hello world")
print reverse("reverse)

does it print both strings in reverse fine? A function should work multiple times


It print those two like this:


I also get an error message at the bottom of my editor that reads:



It seems your function is not working correctly when having to deal with multiple function calls, why could that be?

Please copy paste your full code

None is the default returned value, it seems you only print the reversed string, you do not return it


Thanks for the help, specifically about the lack of ‘return’.

Here’s the code that I ended with:

{def reverse(text):
backwards = []
last = (len(text) - 1)
while last >= 0:
last -= 1
return “” .join(backwards)

print reverse(“Hello World!”)
print reverse(“Happy Birthday!”)}


Seems good, any questions about it?


None right now. Thanks again for your help!



For normal purposes, we generally do not precede a dot with a space.

 "".join()   vs.  "" .join()

It’s just a convention, but one that most people follow so good to be in the habit of.


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