question: PalindromesFor the purpose of this lab: A palindrome is a string such that it reads the same way backward and forward.Fixispalindromesuch that it returns true if a function is a palindrome and false if not
Pleace check the python sheet to be
debugging
def is_palindrome(word: str) -> bool: """ Return True if word is a palindrome >>> is_palindrome("aha") True >>> is_palindrome("boba") False >>> is_palindrome("tattarrattat") True """ # TODO: fix this function so that it works correctly for i in range(len(word) - 1): if word[i] == word[len(word) - 1 - i]: return False return True
Code:
def is_palindrome(word):
for i in range(int(len(word)/2)):
if(word[i]!=word[len(word)-1-i]):
return False
return True
#Testing
print(is_palindrome("aha"))
print(is_palindrome("boba"))
print(is_palindrome("tattarrattat"))
Output:
Hope this helps.
Get Answers For Free
Most questions answered within 1 hours.