forked from kal179/Beginners_Python_Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathis_palindrome.py
More file actions
27 lines (22 loc) · 766 Bytes
/
is_palindrome.py
File metadata and controls
27 lines (22 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Palindrome is a special string, is same if reversed
# e.g. noon, racecar, et cetera
# Notice in above strings, there is no difference between
# string and it's reversed form
# Function checks if given string is a palindrome or not
# string[::-1] is a clever way to reverse string
# string from start index to end index
# whose difference is -1(reverse)
# found on stack overflow, very pythonic
def is_palindrome(s) :
if s[::-1] == s:
return True
return False
# Test
S = raw_input("String: ")
if is_palindrome(S):
print("Results:\n " +S + " is a palindrome string.")
else:
print("Results:\n " + S + " is not a palindrome string.")
# add a loop to play many times(maybe infinite)