Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In python, 8. Write a function called doublePalindrome which is passed a string

ID: 3920320 • Letter: I

Question

In python,

8. Write a function called doublePalindrome which is passed a string and returns True if the

string is a "double" palindrome (the same word forward and backwards and every letter appears

twice in a row. Examples: “aabbccbbaa”, “a”, “”, “ccaattaacc”). Otherwise return False.

"""

# Your function goes here - uncomment the next lines

"""

s = "aabbccddccbbaa"

print("Double palindrome %s ? %s" % (s,doublePalindrome(s)))

s = "aabbcbbaa"

print("Double palindrome %s ? %s" % (s,doublePalindrome(s)))

s = "aa"

print("Double Palindrome %s ? %s" % (s,doublePalindrome(s)))

"""

Explanation / Answer

def doublePalindrome(s):
   i = 0
   j = len(s) -1
   while i < j:
        if s[i] != s[j]:
           return False
        i = i + 1
        j = j -1
   i = 0
   while i < len(s) - 1:
       if s[i] != s[i+1]:
          return False
       i = i + 2
   return True

print(doublePalindrome("aabbaa"))
print(doublePalindrome("abbaa"))

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote