Added doctest in palindrome.py (#172)
* Added doctest in palindrome.py * small change to re run lint_python testpull/181/head
parent
8793610586
commit
0a9135b5b3
|
@ -1,10 +1,22 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
# Palindrome Check Function on Python 3
|
# Palindrome Check Function using Python 3
|
||||||
|
|
||||||
# The Palindrome Algorithm
|
# The Palindrome Algorithm
|
||||||
# this takes in a string and returns a boolean equal to the result of
|
# this takes in a string and returns a boolean equal to the result of
|
||||||
# whether the program is a palindrome or not.
|
# whether the string is a palindrome or not.
|
||||||
|
string_1 = "abba"
|
||||||
|
string_2 = "abbcccbba"
|
||||||
|
string_3 = "abbccbbba"
|
||||||
|
|
||||||
def palindrome(s: str) -> bool:
|
def palindrome(s: str) -> bool:
|
||||||
|
"""
|
||||||
|
>>> palindrome(string_1)
|
||||||
|
True
|
||||||
|
>>> palindrome(string_2)
|
||||||
|
True
|
||||||
|
>>> palindrome(string_3)
|
||||||
|
False
|
||||||
|
"""
|
||||||
# Reverse string using idiomatic python
|
# Reverse string using idiomatic python
|
||||||
reversed_string = s[::-1]
|
reversed_string = s[::-1]
|
||||||
# return the answer, by comparing string and its reverse
|
# return the answer, by comparing string and its reverse
|
||||||
|
@ -22,9 +34,6 @@ def is_palindrome(s: str):
|
||||||
|
|
||||||
# main program
|
# main program
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
string_1 = "abba"
|
|
||||||
string_2 = "abbcccbba"
|
|
||||||
string_3 = "abbccbbba"
|
|
||||||
is_palindrome(string_1)
|
is_palindrome(string_1)
|
||||||
is_palindrome(string_2)
|
is_palindrome(string_2)
|
||||||
is_palindrome(string_3)
|
is_palindrome(string_3)
|
||||||
|
|
Loading…
Reference in New Issue