-1

I made this to reverse a word but am unable to plzz help.

while True:
    word = input("Normal Word: ")
    newWord = ""
    for i in range(len(word)):
        newWord += word[len(word)-(i+1)]
    print("Reversed Word: '" + newWord() + "'\n")

The error says "TypeError: 'str' object is not callable"

Python03
  • 79
  • 1
  • 2
  • 10

1 Answers1

1

The main problem with your code is:

Calling newWord() in the print function instead of simply newWord.


while True:
    word = input("Normal Word: ")
    newWord = ""
    for i in range(len(word)):
        newWord += word[len(word) - (i + 1)]
    print("Reversed Word: '" + newWord() + "'\n")

A possibly more Pythonic solution is:

newWord = word[::-1]
print(newWord)
Ashish Acharya
  • 3,349
  • 1
  • 16
  • 25