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
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.
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...
Write a program that reads a word and then prints the word in reverse separated by...
Write a program that reads a word and then prints the word in reverse separated by a comma. 3 pts Note: No comma at the end of the reversed word. Enter word: Harry The reversed word is: y,r,r,a,H Python keep it simple
Write a Python program that reads in the month, day, and year of a date and...
Write a Python program that reads in the month, day, and year of a date and prints it in the dd/mm/yyyy format or mm/dd/yyyy format, the format depending on the user’s preference. The program also prints the message It is a magic date If the product of month and day is equal to the last two digits of the year. For example, April 20 1980 is a magic date because April (numeric value 4) multiplied by 20 is equal to...
Write a program that takes a string of characters (including spaces) as input, computes the frequency...
Write a program that takes a string of characters (including spaces) as input, computes the frequency of each character, sorts them by frequency, and outputs the Huffman code for each character.   When you are writing your program, you should first test it on a string of 7 characters, so you can check it. PLEASE NOTE: Your program must work for any text that has upper and lower case letters digits 0 - 9, commas, periods, and spaces. Please submit the...
Use Python: # Problem Set 03: - Write a program to input an uncertain string *S*...
Use Python: # Problem Set 03: - Write a program to input an uncertain string *S* of words and space/tab - Remove space/tab in S - Remove identical words - Sort all words in the order of a-z - Print the output strings - Example: - Input String: "hello world and practice makes perfect and hello world again" - Output String: "again and hello makes perfect practice world" - Tips: - use *set* to remove identical words, - use *sorted()*...
Write a Python program that plays a number guessing game with a human user. The human...
Write a Python program that plays a number guessing game with a human user. The human user will think of a number between 1 and 100, inclusive. Then the program has to guess what the user entered. keep track of the number of interaction it takes for the computer to guess the number. sample run: enter number to be guessed:88 output: you entered 88, and it took the program 3 iterations to guess.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT