ΣνΜDr. Sharon's Math PlatformSyvara Learning
Question Bank › 📘 Undergraduate › Programming for Engineers › Q15

Q15 · The function below checks if a string is a palindrome (same forward and backward,…

Testing with Doctest 🟡 Intermediate Coding
Question

The function below checks if a string is a palindrome (same forward and backward, ignoring case and non-alphanumeric characters):

  def is_palindrome(s):
      cleaned = "".join(char for char in s if char.isalnum())
      return cleaned == cleaned[::-1]

(a) Add at least two common case and two edge case doctest examples to the docstring.
(b) There is a hidden bug — the function is case-sensitive. Find and fix it.
(c) Run doctest.testmod(verbose=True) to verify all tests pass.

🔒

Log in to see the worked solution

Enter your email to get started. Your first free solutions in every course unlock as soon as you verify.

Log in or sign up with email
← Previous
Working…