More information
Below is my code. I am in the process of making a small program that finds Palindromes. I want the program to take user input, save it to a variable, and then check for any spaces. If it finds a space to save its index, and then to take it out to check for a Palindromes. Out of curiosity and to further my programming skills, I want to be able to add the space back later while the word is in reverse. For example, nurses run = nursesrun backward and forwards, but I also want to display it backward and add the space back.
word = input("Please enter a word")
storeVal = word.count(" ")
print()
newWord = word.replace(" ", "")
print(newWord)
print()
while True:
if newWord == "":
print("Sorry, but you did not enter a word")
break
elif newWord == newWord[::-1]:
#use the index storeVal and add it in the string to put a space back
print(" is a palidrone")
break
elif newWord != newWord[::-1]:
print("This is not a palidron")
break
else:
print("You have reached an error")
Also, if you have any suggestions for how I can improve my ability to ask this question or a better way I can write this question, please let me know. Thank you for reading.
word[::-1]) after checking if it's a palindrome?while True:and you are not adjusting anything to justify the loop. Remove thewhileline and move the indentation back up of all lines below the line. You do not need the finalelse. Convertelif newWord != newWord[::-1]:toelse: print("This is not a palidron").