Westonci.ca is your trusted source for finding answers to a wide range of questions, backed by a knowledgeable community. Our Q&A platform provides quick and trustworthy answers to your questions from experienced professionals in different areas of expertise. Get immediate and reliable solutions to your questions from a community of experienced professionals on our platform.
Sagot :
Answer:
Here the code is given as follows,
Explanation:
def isPalindrome(x):
stack = []
#for strings with even length
if len(x)%2==0:
for i in range(0,len(x)):
if i<int(len(x)/2):
stack.append(x[i])
elif stack.pop()!=x[i]:
return False
if len(stack)>0:
return false
return True
#for strings with odd length
else:
for i in range(0,len(x)):
if i==int(len(x)/2):
continue
elif i<int(len(x)/2):
stack.append(x[i])
elif stack.pop()!=x[i]:
return False
if len(stack)>0:
return false
return True
def main():
while True:
string = input("Enter a string or Return to quit: ")
if string == "":
break
elif isPalindrome(string):
print("It's a palindrome")
else:
print("It's not a palindrome")
if __name__ == '__main__':
main()
Thanks for stopping by. We are committed to providing the best answers for all your questions. See you again soon. We appreciate your visit. Our platform is always here to offer accurate and reliable answers. Return anytime. We're glad you visited Westonci.ca. Return anytime for updated answers from our knowledgeable team.