s=input("Enter the string\t") a=s.lower() if a[0:]==a[-1:]: print("Yes the string is palindrome") else: print("No the string is not palindrome") what's wrong
Question
s=input("Enter the string\t") a=s.lower() if a[0:]==a[-1:]: print("Yes the string is palindrome") else: print("No the string is not palindrome")
what's wrong
Solution
The code you provided checks if a given string is a palindrome or not. However, there is a syntax error in the code. The correct code is as follows:
- Prompt the user to enter a string:
s = input("Enter the string: ")
- Convert the string to lowercase:
a = s.lower()
- Check if the first and last characters of the string are the same:
if a[0:] == a[-1:]:
- If the condition is true, print that the string is a palindrome:
print("Yes, the string is a palindrome.")
- If the condition is false, print that the string is not a palindrome:
else:
print("No, the string is not a palindrome.")
Make sure to fix the indentation in your code as well.
Similar Questions
word = input("enter a word") word = word.lower() turd = len(word) for i in range(0,turd,1): if word[i] == word[turd-i]: print("palindrome") else: print("no") palindrome()
Write a python program to check the given string is palindrome or not.
12. DS-PythonMCQUNSOLVEDWhich of the following code snippets correctly checks if a string is a palindrome? Answer( Please choose all correct answers ) CLEARword == word[::-1]word == reversed(word) word.sort() == word.sort(reverse=True)word == "".join(reversed(word))
Given an integer x, return true if x is a palindrome, and false otherwise. Example 1:Input: x = 121Output: trueExplanation: 121 reads as 121 from left to right and from right to left.Example 2:Input: x = -121Output: falseExplanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.Example 3:Input: x = 10Output: falseExplanation: Reads 01 from right to left. Therefore it is not a palindrome.
Write a programme to check whether given input is palindrome or notConstraintsABC != PalindromeMAM == Palindrome123 != Palindrome151 == Palindrome
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.