Last active
June 17, 2022 06:04
-
-
Save agung037/85843eedd5fc287bef1f8ec68ef6f41c to your computer and use it in GitHub Desktop.
program untuk mencari palindrome
This file contains hidden or 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
def palindrome(target): | |
depan = [] | |
belakang = [] | |
hasil = [] | |
for i in range(len(target) - 1): | |
for j in range(len(target) - 1): | |
if len(target[i:j+2]) >= 3: | |
depan.append(target[i:j+2].lower()) | |
belakang.append(target[i:j+2][::-1].lower()) | |
for i in depan: | |
if i in belakang: | |
hasil.append(i) | |
if not hasil: | |
return "tidak ada palindrome" | |
return max(hasil, key=len) | |
while True: | |
t = input("Masukan kata / kalimat : ") | |
print(palindrome(t)) | |
print("-----------") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment