forked from geekcomputers/Python
-
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.
whether the string is Symmetrical or Palindrome
Python program to check whether the string is Symmetrical or Palindrome
- Loading branch information
Showing
1 changed file
with
53 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,53 @@ | ||
def palindrome(a): | ||
|
||
mid = (len(a)-1)//2 | ||
start = 0 | ||
last = len(a)-1 | ||
flag = 0 | ||
|
||
while(start<mid): | ||
|
||
if (a[start]== a[last]): | ||
|
||
start += 1 | ||
last -= 1 | ||
|
||
else: | ||
flag = 1 | ||
break; | ||
|
||
if flag == 0: | ||
print("The entered string is palindrome") | ||
else: | ||
print("The entered string is not palindrome") | ||
|
||
def symmetry(a): | ||
|
||
n = len(a) | ||
flag = 0 | ||
|
||
if n%2: | ||
mid = n//2 +1 | ||
else: | ||
mid = n//2 | ||
|
||
start1 = 0 | ||
start2 = mid | ||
|
||
while(start1 < mid and start2 < n): | ||
|
||
if (a[start1]== a[start2]): | ||
start1 = start1 + 1 | ||
start2 = start2 + 1 | ||
else: | ||
flag = 1 | ||
break | ||
|
||
if flag == 0: | ||
print("The entered string is symmetrical") | ||
else: | ||
print("The entered string is not symmetrical") | ||
|
||
string = 'amaama' | ||
palindrome(string) | ||
symmetry(string) |