Last active
January 16, 2023 13:50
-
-
Save YamatoDX/8a90d80390340324f8f2b44121356096 to your computer and use it in GitHub Desktop.
palindrome code with testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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