You should be able to answer this question after you have studied up to Chapter 4.
This question tests the following learning outcomes:
Understand the common general-purpose data structures, algorithmic techniques and complexity classes.
Develop and apply algorithms and data structures to solve computational problems.
Write readable, tested, documented and efficient Python code.
Exercise 4.8.4 in the course book asked you to implement a function that decides whether a string is a palindrome without modifying the input string. For this
question, do the exercise, but modify it to check whether a palindrome number is present as a string with a length greater than 1. Your code should return a
Boolean False if any leading zeros or non-numeric characters are in the string.
For example, '1221' and '10201' are palindrome numbers but '010' and '011' are not; both would return Boolean False because both have leading zeroes
regardless of whether the input is a palindrome before or after the leading zero is taken into account. A Boolean False would be returned for 'a1221', 'a1221a',
and '12.21', because 'a' and '.' are non-numeric characters.
Write code below that adheres to M269 coding style (defined in course book section 5.3). The function should:
be named is_palindrome
accept a single string parameter with a length greater than 1
return a Boolean: True if the string is a palindrome based on the defined criteria; False otherwise.
You can use the tests below to help check if your code is working. NOTE that failing the tests is a clear indication you code is faulty, but passing the tests is
NOT a guarantee it is correct. Your tutor may run additional tests.
#Write your answer here
#Use these tests
test_table = [
["Is palindrome", "1001", True],
["Is not palindrome", "1010", False],
["Palindrome with middle digit", "10101", True]
]
test(is_palindrome, test_table)