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
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...
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...
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 =...
Java Program : Please save the program with the name ‘Dstring.java’ Write a program that reads...
Java Program : Please save the program with the name ‘Dstring.java’ Write a program that reads a string from the keyboard. If the length of the string is an even number, your program should split the string into two strings of equal length. If the length of the string is odd, your program should split the string into two strings where the first part has one more character than the second part. Your program should output the two strings it...
Using the facilities of numpy, write a python program that reads the input signal as a...
Using the facilities of numpy, write a python program that reads the input signal as a space separated sequence of numbers on one line, and the system impulse response as a space separated sequence of numbers on the next line, and outputs (on one line) the output of the DT LTI system. The input lines should be interpreted as x[0] x[1] x[2] ... x[N-1] h[0] h[1] h[2] ... h[M-1] and the output should be produced in the same order: y[0]...
Write a program that accepts an input string from the user and converts it into an...
Write a program that accepts an input string from the user and converts it into an array of words using an array of pointers. Each pointer in the array should point to the location of the first letter of each word. Implement this conversion in a function str_to_word which returns an integer reflecting the number of words in the original string. To help isolate each word in the sentence, convert the spaces to NULL characters. You can assume the input...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT