forked from jainaman224/Algo_Ds_Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
check whether a string is palindrome (jainaman224#2402)
* pallindrome string python * Update and rename pallindrome_string.py to palindrome_string.py Fixed Typo in file name * Update palindrome_string.py
- Loading branch information
1 parent
68a0a29
commit 5eae7fb
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Python program to find whether a string is a palindrome or not | ||
|
||
# Function to reverse a String | ||
def reverse(str): | ||
|
||
# Initialize variable | ||
rev = "" | ||
|
||
for i in range (len(str)-1, -1, -1): | ||
rev = rev + str[i] | ||
return rev | ||
|
||
|
||
# --- main --- | ||
string = raw_input(("Enter a string: ")) #User Input | ||
|
||
a = reverse(string) #Function call | ||
|
||
if(a == string): #Comparing the reversed String with original String | ||
print("String entered is palindrome!") | ||
else: | ||
print("String entered is not a palindrome!") | ||
|
||
''' | ||
TEST CASES | ||
Enter a string: affcffa | ||
String entered is palindrome! | ||
Enter a string: abbcd | ||
String entered is not a palindrome! | ||
''' |