Question

question: PalindromesFor the purpose of this lab: A palindrome is a string such that it reads...

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

Homework Answers

Answer #1

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.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
A palindrome is a word, phrase, or sequence that reads the same backward as forward, e.g.,...
A palindrome is a word, phrase, or sequence that reads the same backward as forward, e.g., madam. Write a PHP function that checks whether a passed string is a palindrome or not, then call this function to check if "madam" is a palindrome
Using c++ Valid Palindrome In this assignment, you need to implement a bool isPalindrome(string s) function....
Using c++ Valid Palindrome In this assignment, you need to implement a bool isPalindrome(string s) function. Given a string s, isPalindrome(s) can determine if s is a palindrome, considering only alphanumeric characters and ignoring cases. Note: for the purpose of this problem, we define empty string as valid palindrome. Example 1: Input: ”A man, a plan, a canal: Panama” Output: true Example 2: Input: ”race a car” Output: false Requirement: There are many methods to check if a string is...
A palindrome is a word or a phrase that is the same when read both forward...
A palindrome is a word or a phrase that is the same when read both forward and backward. Examples are: "bob," "sees," or "never odd or even" (ignoring spaces). Write a program whose input is a word or phrase, and that outputs whether the input is a palindrome. user_string = input() low = 0 high = len(user_string)-1 result = True while low < high: if (user_string[low] == ' '): low += 1 elif (user_string[low]!=user_string[high]): result = False break low +=...
Java Please [(1)] A palindrome is a string that reads the same forwards as backwards. Using...
Java Please [(1)] A palindrome is a string that reads the same forwards as backwards. Using only a fixed number of stacks and queues, the stack and queue ADT functions, and a fixed number of int and char variables, write an algorithm to determine if a string is a palindrome. Assume that the string is read from standard input one character at a time. The algorithm should output true or false as appropriate [(2)] Let Q be a non-empty queue,...
can you please do this lab? use lunix or C program its a continuation of a...
can you please do this lab? use lunix or C program its a continuation of a previous lab. the previous lab: Unix lab 4: compile and link multiple c or c++ files Please do the following tasks step by step: create a new directory named by inlab4 enter directory inlab4 create a new file named by reverse.c with the following contents and then close the file: /*reverse.c */ #include <stdio.h> reverse(char *before, char *after); main() {       char str[100];    /*Buffer...
#Write a function called has_a_vowel. has_a_vowel should have #one parameter, a string. It should return True...
#Write a function called has_a_vowel. has_a_vowel should have #one parameter, a string. It should return True if the string #has any vowels in it, False if it does not. def has_a_vowel(a_str): print("Starting...") for letter in a_str: print("Checking", letter) if letter in "aeiou": print(letter, "is a vowel, returning True") return True else: print(letter, "is not a vowel, returning False") return False print("Done!")       #Below are some lines of code that will test your function. #You can change the value of...
question : Phone Number CheckingAlice has been having trouble with people filling her website’s form incorrectly,...
question : Phone Number CheckingAlice has been having trouble with people filling her website’s form incorrectly, especially with phone numbers. She’d like tomake sure a user’s phone number input only has digits (other than -) and is exactly 10 digits long.Finishvalidphonenumber(string)such that the function returns True if a phone number is valid, and False if not. def valid_phone_number(number: str) -> bool:     """     Return True if the number is a valid phone number. A valid phone number:     1)...
convert this code to accept int value instead of float values using python. Make sure to...
convert this code to accept int value instead of float values using python. Make sure to follow the same code. do not change the steps and make sure to point to what code you replaced. make sure to have 2 files Method:----------------------- #define a python user difined method def get_float_val (prompt): is_num = False str_val = input (prompt) #prming read for our while #while is_num == False: (ignore this but it works) old school while not is_num: try: value =...
write a code in python Write the following functions below based on their comments. Note Pass...
write a code in python Write the following functions below based on their comments. Note Pass is a key word you can use to have a function the does not do anything. You are only allowed to use what was discussed in the lectures, labs and assignments, and there is no need to import any libraries. #!/usr/bin/python3 #(1 Mark) This function will take in a string of digits and check to see if all the digits in the string are...
Create an add method for the BST (Binary Search Tree) class. add(self, new_value: object) -> None:...
Create an add method for the BST (Binary Search Tree) class. add(self, new_value: object) -> None: """This method adds new value to the tree, maintaining BST property. Duplicates must be allowed and placed in the right subtree.""" Example #1: tree = BST() print(tree) tree.add(10) tree.add(15) tree.add(5) print(tree) tree.add(15) tree.add(15) print(tree) tree.add(5) print(tree) Output: TREE in order { } TREE in order { 5, 10, 15 } TREE in order { 5, 10, 15, 15, 15 } TREE in order {...