-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 # Returning reversed number | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this line |
||
|
||
# --- main --- | ||
string=raw_input(("Enter a string: ")) #User Input | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. keep space around = |
||
|
||
a = reverse(string) #Function call | ||
|
||
if(a==string): #Comparing the reversed String with original String | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. keep space around == There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @asha15, I have made the changes. Plz review |
||
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! | ||
''' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep a space after comma