write aprogram to check whether the given string is a palindrone Or not in python string program
Answers
Answered by
1
Required Answer:-
Question:
- Write a python program to check whether a given string is palindrome or not.
Solution:
1. Using loops.
s=input("Enter a string: ")
m=""
for i in range(len(s)-1,-1,-1):
m+=s[i]
if s==m:
print("Palindrome.")
else:
print("Not Palindrome.")
2. Using string slicing.
s=input("Enter a String: ")
if s==s[::-1]:
print("Palindrome.")
else:
print("Not Palindrome.")
Algorithm:
- START
- Ask the user to enter a string.
- Find the reverse of the string.
- Check if the reversed string and the original string are same or not. If true, then the string is palindrome else not.
- Display the result.
- STOP.
Check out the attachment for output ☑.
Attachments:
Similar questions