Learn practical skills, build real-world projects, and advance your career
Created 3 years ago
#pali and symetric
x=input()
y=x[::-1]
if x==y:
print("palindrome")
else:
print("not a palindrome")
z=len(x)/2
# Python program to demonstrate
# symmetry and palindrome of the
# string
# Function to check whether the
# string is plaindrome or not
def palindrome(a):
# finding the mid, start
# and last index of the string
mid = (len(a)-1)//2
start = 0
last = len(a)-1
flag = 0
# A loop till the mid of the
# string
while(start<mid):
# comparing letters from right
# from the letters from left
if (a[start]== a[last]):
start += 1
last -= 1
else:
flag = 1
break;
# Checking the flag variable to
# check if the string is palindrome
# or not
if flag == 0:
print("The entered string is palindrome")
else:
print("The entered string is not palindrome")
# Function to check whether the
# string is symmetrical or not
def symmetry(a):
n = len(a)
flag = 0
# Check if the string's length
# is odd or even
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
# Checking the flag variable to
# check if the string is symmetrical
# or not
if flag == 0:
print("The entered string is symmetrical")
else:
print("The entered string is not symmetrical")
# Driver code
string = 'amaama'
palindrome(string)
symmetry(string)
The entered string is palindrome
The entered string is symmetrical
#least occurance
x='aditya'
list={}
for i in x:
if i in list:
list[i]+=1
else:
list[i]=1
res=max(list,key=list.get)
print(res)
y
arr=list(map(int,input().split(',')))
num1=sum(arr[:arr.index(5)])+sum(arr[arr.index(8)+1:])
l1=arr[arr.index(5):arr.index(8)+1]
num2=''
for i in l1:
num2+=str(i)
print(int(num2)+num1)
3,2,5,2,5,1,8,4
52527
def next_palindrome(x):
while True:
rev=int(str(x)[::-1])
if rev==x:
return x
x+=1
x=int(input())
next_palindrome(x)
1222
1331