Question

Write a Python program that reads in a string and determines whether the string is a...

Write a Python program that reads in a string and determines whether the string is a palindrome or not. note that a sentence that reads the same forwards and backwards by resequencing the spaces is also a palindrome and your program should consider this.

sample run

enter string: mom

output: mom is a polindrame

enter string: a nut for a jar of tuna

output: a nut for a jar of tuna is a palindrome

Homework Answers

Answer #1
string = input("enter string: ")
s = string.lower()
s = s.replace(" ", "")
low = 0
high = len(s) - 1
result = True
while(low<high):
    if(s[low]!=s[high]):
        result = False
    low+=1
    high-=1
if result:
    print(string, "is a palindrome")
else:
    print(string, "is not a palindrome")

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
Write a program that determines whether an input string a palindrome; that is whether it can...
Write a program that determines whether an input string a palindrome; that is whether it can be read the same way forward and backward. At each point, you can read only one character of the input string; do not use an array to first store this string and then analyze it (except, possibly in a stack implementation). Consider using multiple stacks. PLEASE PROVIDE A PSEUDOCODE
python problem: ( use a loop to read each character from the string and insert into...
python problem: ( use a loop to read each character from the string and insert into the stack) 1. The function main a5.py continually asks the user for a string, and calls isPalindrome to check whether each string is a palindrome. A palindrome is a word or sequence that reads the same backward as forward, e.g., noon, madam or nurses run. 2. Your function must ignore spaces: when the user enters 'nurses run', the function returns True, to indicate that...
Write a JAVA program that reads in a string from standard input and determines the following:...
Write a JAVA program that reads in a string from standard input and determines the following: - How many vowels are in the string (FOR THE PURPOSE OF THIS PROGRAM 'Y' is NOT considered a vowel)? - How many upper case characters are in the string? - How many digits are in the string? - How many white space characters are in the string? - Modify the program to indicate which vowel occurs the most. In the case of a...
Write a method public static boolean isPalindrome(String input) that uses one or more stacks to determine...
Write a method public static boolean isPalindrome(String input) that uses one or more stacks to determine if a given string is a palindrome. [A palindrome is a string that reads the same forwards and backwards, for example ‘racecar’, ‘civic’]. Make sure that your method works correctly for special cases, if any. (b) What is the big-O complexity of your method in terms of the list size n.
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,...
Write a Python program that splits, doubles, and reverse each input string entered. For each string,...
Write a Python program that splits, doubles, and reverse each input string entered. For each string, split it at the given integer, and then output it in format as shown below. Convert all stings entered to uppercase for output. Assume string length is greater than the split value. Refer to the sample output below. Sample Runs: Enter a string: holiday Enter the number to split on: 3 HOL-YADI-LOH-IDAY Enter a string: TATTARRATTAT Enter the number to split on: 6 TATTAR-TATTAR-RATTAT-RATTAT...
Python Programming Build a python programming that asks the user for a three-letter substring. The program...
Python Programming Build a python programming that asks the user for a three-letter substring. The program should then proceed to read the file strings.txt. Each line in strings.txt will contain a string. Your program should then test to see how many non-overlapping occurrences of the three-letter substring occur in that string and test whether the string is a palindrome. The program should then proceed to create an output file string_stats.txt, which contains the original data on one line and the...
Write a program in c++ that uses a stack to test whether a given string is...
Write a program in c++ that uses a stack to test whether a given string is a palindrome.
Create a function in MIPS using MARS to determine whether a user input string is a...
Create a function in MIPS using MARS to determine whether a user input string is a palindrome or not. Assume that the function is not part of the same program that is calling it. This means it would not have access to your .data segment in the function, so you need to send and receive information from the function itself. The program should be as simple as possible while still using necessary procedures. Follow the instructions below carefully. Instructions: ●...
Write a program that reads a binary string (string of 0’s and 1’s) converting the binary...
Write a program that reads a binary string (string of 0’s and 1’s) converting the binary value into decimal. Allow the user to type in as many numbers as they want (one at a time) and end the program when they type in “0”. Use Horner’s method (given in step 3, below) to convert from binary to decimal. Sample Run Binary to Decimal Conversion Enter a binary string: 1101 1101 = 13 decimal Enter a binary string: 10011001 10011001 =...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT