Wednesday, October 5, 2022

Check if a string is Palindrome in Python

 metin = input("Enter string for palindrome check: ")

print(metin)
ters_metin = ""
yeni_metin = ""

if len(metin) == 0:
print("Not a palindrome")

# To remove any empty character from the string
for m in metin:
if m != " ":
yeni_metin = yeni_metin + m
else:
continue

# to reverse the string
for x in range(1,len(yeni_metin)+1):
ters_metin = ters_metin + yeni_metin[-x]

print(metin)
print(yeni_metin)
print(ters_metin)
if ters_metin == yeni_metin:
print("input string is a palindrome")
else:
print("input string is not a palindrome")

Reverse a String in Python without using any built-in Functions

 metin = """This text will be reversed without using any built-in functions"""

ters_metin = ""
i = 0
y = []
a = [0]
for x in metin:
i = i+1
a[0] = i
y = y + a

for z in y:
ters_metin = ters_metin + metin[-z]
print(metin)
print(ters_metin)