Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check whether a string is palindrome #2402

Merged
merged 3 commits into from
Mar 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Palindrome/palindrome_string.py
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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this line


# --- 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!
'''