import sys def is_palindrome(string): string = string.lower() low = 0 high = len(string)-1 while(low
import sys
def is_palindrome(string):
string = string.lower()
low = 0
high = len(string)-1
while(low<high):
if not string[low].isalpha():
low += 1
elif not string[high].isalpha():
high += 1
else:
if(string[low]!=string[high]):
return False
low+=1
high-=1
return True
def main():
if len(sys.argv)==2:
string = sys.argv[1]
if is_palindrome(string):
print("It's a palindrome!")
else:
print("It's not a palindrome!")
main()
when running python3 palindrome.py 'Ed, I saw Harpo Marx ram Oprah W. aside' it should say
- It's a palindrome!
when running python3 palindrome.py 'Dennis, Nell, Edna, Leon, Nedra, Anita, Rolf, Nora, Alice, Carol, Leo, Jane, Reed, Dena, Dale, Basil, Rae, Penny, Lana, Dave, Denny, Lena, Ida, Bernadette, Ben, Ray, Lila, Nina, Jo, Ira, Mara, Sara, Mario, Jan, Ina, Lily, Arne, Bette, Dan, Reba, Diane, Lynn, Ed, Eva, Dana, Lynne, Pearl, Isabel, Ada, Ned, Dee, Rena, Joel, Lora, Cecil, Aaron, Flora, Tina, Arden, Noel, and Ellen sinned'
it should say
- It's a palindrome!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images