Advertisement
Guest User

Untitled

a guest
Feb 18th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. # While "keepGoing" is "True", we will keep processing user input.
  2. while keepGoing :
  3.  
  4.  
  5. #Getting the string from the user
  6.  
  7. string = input ("Please enter the string: ")
  8.  
  9. #Generating a cleaned-up version of the inputted string
  10.  
  11. lower_string = string.lower()
  12. clean_string = lower_string.replace (" ", "")
  13.  
  14. #Print the cleaned-up version of the inputted string
  15.  
  16. print ("The cleaned-up string is:", clean_string)
  17.  
  18. #Determine the length of the word
  19.  
  20. length= len(clean_string)
  21. half_length = int(length/2)
  22. print ("It has", length, "letters.")
  23.  
  24. #Determined if the cleaned-up string is a palindrome through Boolean variable
  25.  
  26. for i in range(0, half_length):
  27. if string [i] == string[len(string)-i-1]:
  28. is_palindrome = 1
  29.  
  30. else:
  31. is_palindrome = 0
  32.  
  33. if is_palindrome == 1:
  34.  
  35. mirrored = clean_string [0:half_length]
  36.  
  37. print ('This IS a palindrome. The mirrored part is "', mirrored, '".')
  38. else:
  39. print("This is NOT a palindrome.")
  40.  
  41. #Ask the user if they want to continue inputting another string to see if it is a palindrome
  42.  
  43. response = input("Would you like to check another string? [Yes/ No] ")
  44.  
  45. if response== "No":
  46. keepGoing = False
  47. print ("Goodbye.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement