Question

In: Computer Science

2. Palindromes A palindrome is a word that reads the same forwards and backwards. For example,...


2.


Palindromes


A palindrome is a word that reads the same forwards and backwards. For example,


\aibohphobia" (the irrational fear of palindromes) is a word that reads the same


forwards and backwards. Write a function called


isPalindrome()


that accepts a


string as a parameter and returns True if the string is a palindrome, False otherwise.


Using the function you created, write a program

Python home work

Python

Solutions

Expert Solution

def isPalindrome(str): #function definition
for i in range(0, int(len(str)/2)): # Run loop from 0 to len/2
if str[i] != str[len(str)-i-1]: #checking whether characters are equal or not
return 0
return 1
s = raw_input("Enter the string: ") #taking input as a string
check = isPalindrome(s) #function calling
if (check):
print("True")
else:
print("False")

The above picture is about python program to check whether given string is palindrome or not by using function


Related Solutions

A palindrome prime is a prime number that reads the same forwards or backwards. An example...
A palindrome prime is a prime number that reads the same forwards or backwards. An example of a palindrome prime is 131. Write a method with the following signature for determining if a given number is a palindrome prime. public static boolean isPallyPrime(int nVal) Note: For this assignment you are not allowed to use the built in Java class Array as part of your solution for any of these questions. Your Method signatures must be the same as given here.
IN JAVA - [(1)] A palindrome is a string that reads the same forwards as backwards....
IN JAVA - [(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...
#Python: A palindrome is a sequence of characters that reads the same backwards as forwards. For...
#Python: A palindrome is a sequence of characters that reads the same backwards as forwards. For example, ‘Eve’, ‘madam’, and 20502, are palindromes. Write a function called testPalindrome() that asks the user to input a string and returns if that string is a palindrome with the output as follows, without red: >>> Please enter a string: eve Your string "eve" is a palindrome. >>> testPalindrome() Please enter a string: end Your string "end" is not a palindrome. >>> testPalindrome() Please...
python question A word is a palindrome if it the same read forwards and backwards. We...
python question A word is a palindrome if it the same read forwards and backwards. We will call a word a fuzzy palindrome if it is the same read forwards and backwards, except for possible differences in case. For example, both 'tattarrattat' and 'TaTtArRAttat' are fuzzy palindromes. Define a function is_fuzzy_palindrome that returns True if and only if its argument is a fuzzy palindrome. This method may be useful: S.lower() -> str : Return a copy of the string S...
making a python code for this: A palindrome is a sequence that reads the same backwards...
making a python code for this: A palindrome is a sequence that reads the same backwards as forwards. Numbers can also be palindromes if we consider their digits as a sequence, for example 12121 and 8228 are palindromes. We can find palindromes from an initial seed number using the reverse and add method: choose a number, reverse its digits and add it to the original. If the sum is not a palindrome (which means, it is not the same number...
A Palindromic number is one that reads the same backwards and forwards. Write a MATLAB function...
A Palindromic number is one that reads the same backwards and forwards. Write a MATLAB function (call it palin.m) that takes as input a positive integer, and returns 1 (true) if it is palindromic, 0 (false) if it is not.  
JAVA Palindrome Detector A palindrome is any word, phrase, or sentence that reads the same forward...
JAVA Palindrome Detector A palindrome is any word, phrase, or sentence that reads the same forward or backward. Here are some well-known palindromes: Able was I, ere I saw Elba A man, a plan, a canal, Panama Desserts, I stressed Kayak Write a boolean method that users recursion to determine where a String argument is a palindrome. The method should return true if the argument reads the same forward and backward. Demonstrate the method in a program. Include the following...
A palindrome is a word or phrase, which reads the same backward or forward. Write a...
A palindrome is a word or phrase, which reads the same backward or forward. Write a program that prompts the user for a string of characters terminated by a period and determines whether the string (without the period) is a palindrome. IMP: Assume that the input contains only letters and blanks. Assume also that the input is at most 30 characters long. Use an array of characters of size 30 to store the input! Disregard blanks when deciding if the...
In Java A palindrome is a word or sequence of characters which reads the same backward...
In Java A palindrome is a word or sequence of characters which reads the same backward and forward, such as madam, dad, racecar, 5885. In java Write a program that asks user to enter a word and prints if the word is a palindrome or not.
A palindrome is a string that reads the same forward and backward, for example, radar, toot,...
A palindrome is a string that reads the same forward and backward, for example, radar, toot, and madam. Your task is to construct a python algorithm to receive as input a string of characters and check whether it is a palindrome using a stack and a queue. Your ADTs contains the following methods: Queue Queue() – constructor enqueue(e) – enqueue an element dequeue(e) – dequeue an element len() – returns the number of elements in the queue Stack Stack() -...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT