Palindrome for check string On Python
PALINDROME
Hi Friends..Welcome to this blog
I am PyKar
Here i show you How to check given string is palindrome or not
If you don't know about palindrome Google on it...
Copy that Py Code and Paste Below mention website and run it...
website: https://repl.it/languages/python3
Here is this code
I have make it with 2 different ways...
CODE 1:
import sys
class Solution:
def __init__(self):
self.stack = []
self.queue = []
def pushCharacter(self, ch):
self.stack.append(ch)
def enqueueCharacter(self,s):
self.queue.insert(0,s)
def popCharacter(self):
self.stack.pop()
def dequeueCharacter(self):
self.queue.pop()
s = input('Enter your string: ')
obj = Solution()
isPalindrome = True
n = len(s)
print(list_s)
for i in range(n):
obj.pushCharacter(s[i])
obj.enqueueCharacter(s[i])
for i in range(n//2):
if obj.popCharacter() != obj.dequeueCharacter():
isPalindrome = False
break
if isPalindrome:
print(f'Given string {s} is a Palindrome')
else:
print(f'Given string {s} is not a Palindrome')
CODE 2:
This is method is very simplest... without ref class object
s = input('Enter your string: ')
list_s = [i for i in s]
n = len(list_s)
i = -1
newstring = ''
while i >= (-n):
newstring += list_s[i]
i += -1
print(newstring)
if newstring in s:
print(f'Given string {s} is a Palindrome')
else:
print(f'Given string {s} is not a Palindrome')
i hope you get it ...
See you
By
PyKar
Comments
Post a Comment