Files
freecodecamp--freecodecamp/curriculum/challenges/english/blocks/daily-coding-challenges-python/69b58ce40693f140c84c8559.md
T
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

1.6 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
69b58ce40693f140c84c8559 Challenge 240: Palindrome Characters 29 challenge-240

--description--

Given a string, determine if it's a palindrome and return the middle character (if it's odd length) or middle two characters (if it's even).

  • A palindrome is a string that is the same forward and backward.
  • If it's not a palindrome, return "none".

--hints--

palindrome_locator("racecar") should return "e".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(palindrome_locator("racecar"), "e")`)
}})

palindrome_locator("level") should return "v".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(palindrome_locator("level"), "v")`)
}})

palindrome_locator("freecodecamp") should return "none".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(palindrome_locator("freecodecamp"), "none")`)
}})

palindrome_locator("noon") should return "oo".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(palindrome_locator("noon"), "oo")`)
}})

palindrome_locator("11100111") should return "00".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(palindrome_locator("11100111"), "00")`)
}})

--seed--

--seed-contents--

def palindrome_locator(s):

    return s

--solutions--

def palindrome_locator(s):
    if s != s[::-1]:
        return "none"
    mid = len(s) // 2
    return s[mid] if len(s) % 2 == 1 else s[mid - 1] + s[mid]