I'm tasked with making a program that finds the longest palindrome in a given text that doesn't contain more than 3 of the same letters.
#This program needs to find the longest palindrome
# that does not contain the same letter more than 3 times
def ispalin(z):
y = ""
for i in range(len(z) - 1, -1, -1):
if z[i] != " ":
y += z[i]
if z == y:
return True
#I'm thinking something needs to be added here, so i can return false
#if the palindrome has more than 3 of the same letter.
else:
return False
def haspalin(z, k):
for i in range(0, len(z) - k + 1):
if ispalin(z[i:i + k]):
return (z[i:i + k])
return False
S = input("Write your text:")
for i in range(len(S), 0, -1):
z = haspalin(S, i)
if z:
print(z)
break