7/15 reverse


#1

Hi, I was wondering if anyone could tell me why my code stops at "!" instead of looping through the amount of times needed to get "!nohtyP"? Any and all feedback is appreciated. Thanks!

*astericks are used to show indentation (not on my actual code).

def reverse(text):
    reverse= ""
    for i in range(len(text)):
         count=1
         reverse += text[len(text)-count]
         count+=1
         return reverse

15/7 reverse not passing
#2

I'm also just a beginner like you so this solution might not work. Your variable count
= 1 is inside the for loop. It should be outside or it will keep resetting to 1 each loop and therefore always output the same letter.


#3

Hi, I understand almost all your function, except for that "+" in "count+=1". Could you tell me what is it for?


#4

There are two problems, first off, i hope you return is indented differently. I would put it on the same indent level as your for loop, so it returns the reversed text after it finished the for loop, and not in the first run (function ends when return is reached)

I would define count (count = 1) before your for loop, not in your for loop, otherwise count is set to 1 each run of your for loop, which is going to do you reverse no good. If you take this steps, it should work, if not, post an updated version of your code.

for next time, use one of the two following options to make your code/indent is visible (so you don't have to use asterixs):

select your code and press ctrl + shift + c (or cmd + shift + c if you use a mac)

if this instructions are unclear, you can also insert 3 backticks before and after your code, like so:

```
<p>visible</p>
```

the backtick is located above the tab key on your keyboard


#5

You keep resetting count to 1 every time it goes through the loop try moving out of the for loop.


#7

Thanks yusrighouse! That def was the problem! :slightly_smiling: