0

Once we reverse each character, how are we going to reprint the word? so for each reverse character I get, i will put it into a list and then I will iterate through that list and print each on a single line and no end space


def reverseString():
    word = input("Gimme a word and I will reverse the word: ")
    low = 0
    high = len(word) - 1
    for i in range(len(word) - 1):
        while low < high:
            word[i] = word[len(word) - i]
            print(word[i], end="")

I am not really sure if I should add each reversing character into a list and print out that list. Thank you so much. The error I keep getting is that string index is out of range. I would really appreciate any help!

Prune
  • 75,308
  • 14
  • 55
  • 76
Killua87
  • 69
  • 7
  • Trace the subscript values you're using. On the very first iteration of your `for` loop, you try to access `word[len(word)]` (since `i` is 0`. This is your index out of range. – Prune Feb 12 '21 at 00:49
  • Also notice that your `while` is an infinite loop. `low` is always lower than `high`, so there is no way to exit the loop. – Prune Feb 12 '21 at 00:50
  • use `print()` to see values in variables in different lines - it helps to see where is the problem. – furas Feb 12 '21 at 02:32

0 Answers0