Skip to content

Instantly share code, notes, and snippets.

@YamatoDX
Last active January 16, 2023 13:50
Show Gist options
  • Save YamatoDX/8a90d80390340324f8f2b44121356096 to your computer and use it in GitHub Desktop.
Save YamatoDX/8a90d80390340324f8f2b44121356096 to your computer and use it in GitHub Desktop.
palindrome code with testing
while True:
myInput = input("Enter your string please: \n");
if(myInput.lower() == "exit"):
print("Exiting programm...............");
break;
result = palindromeWord(myInput)
if result == True:
print(f'{myInput} is palindrome')
elif result == False:
print(f'{myInput} is not a palindrome')
else:
print(f'{myInput} is not a string')
def palindromeWord(strInput):
if (isinstance(strInput, (str)) == False):
return None
if len(strInput) == 0 or len(strInput) == 1:
return True
left = 0;
right = len(strInput) - 1
while (left < right):
if(strInput[left] != strInput[right]):
return False
left = left + 1
right = right - 1
return True
allInputs = ["abba", "abcd", "efggfe", "asddsa", "xcvbnmj", 1232, 9090909];
for eachInput in allInputs:
result = palindromeWord(eachInput)
print(f'result of {eachInput} is {result}')
counter = 3
while(counter != 0):
myInput = input("Enter your string please: \n");
result = palindromeWord(myInput)
if result == True:
print(f'{myInput} is palindrome')
elif result == False:
print(f'{myInput} is not a palindrome')
else:
print(f'{myInput} is not a string')
counter = counter - 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment