Skip to content

Instantly share code, notes, and snippets.

@timeowilliams
Created September 18, 2020 16:16
Show Gist options
  • Save timeowilliams/bf63003f7302b19435de1fd1deb81e60 to your computer and use it in GitHub Desktop.
Save timeowilliams/bf63003f7302b19435de1fd1deb81e60 to your computer and use it in GitHub Desktop.
Practice Python 6: Is it a palindrome?
#a = [5, 10, 15, 20, 25, 30, 35, 40]
#b = a[::-1]
#print(b)
isPalindrome = input('Please enter a word: ')
isPalindrome1 = list(isPalindrome) # Converting string to list
isPalindrome2 = isPalindrome1[::-1] # Secondary list for comparison
#for i in isPalindrome1: # This is iterating automatically, due to the for loops nature
i = 0
palindrome = []
while i < len(isPalindrome):
if isPalindrome1[i] == isPalindrome2[i]: #Integers are fine, but elements in lists cannot be compared as an index.
palindrome.append(isPalindrome1[i])
i += 1
if i == len(isPalindrome):
print('This word is a palindrome')
else:
print('This word is not a palindrome')
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment