diff --git a/challenge_13/python/alexbotello/README.md b/challenge_13/python/alexbotello/README.md new file mode 100644 index 000000000..caf15d5f2 --- /dev/null +++ b/challenge_13/python/alexbotello/README.md @@ -0,0 +1,23 @@ +# Integer Palindrome +###### Language Version (Python 3.6.0) + + +First, we initialize a int variable ```reverse``` and set it equal to zero. As +well as make a copy variable of the integer input ```num2```. Using a while +loop, our algorithm will continue until ```num2``` is equal to zero. + +Run ```palin.py``` to test your implementation +``` +456070654 + +True +``` + +Run ```tests.py``` to check against unit test +``` +....... +---------------------------------------------------------------------- +Ran 7 tests in 0.001s + +OK +``` diff --git a/challenge_13/python/alexbotello/src/palin.py b/challenge_13/python/alexbotello/src/palin.py new file mode 100644 index 000000000..6e86b888a --- /dev/null +++ b/challenge_13/python/alexbotello/src/palin.py @@ -0,0 +1,21 @@ +# Integer Palindrome + +def is_palindrome(num): + """ + Returns True if integer is a Palindrome + """ + reverse = 0 + num2 = num + + while num2 > 0: + # Finds the last digit of num2, removes it, and adds the + # digit to the reverse variable + reverse = (10*reverse) + num2%10 + num2 //= 10 + + return True if reverse == num else False + +if __name__ == "__main__": + num = int(input()) + print() + print(is_palindrome(num)) diff --git a/challenge_13/python/alexbotello/src/tests.py b/challenge_13/python/alexbotello/src/tests.py new file mode 100644 index 000000000..82d40ca1a --- /dev/null +++ b/challenge_13/python/alexbotello/src/tests.py @@ -0,0 +1,28 @@ +import unittest +from palin import is_palindrome + +class Tests(unittest.TestCase): + def test_1(self): + self.assertEqual(is_palindrome(1112111), True) + + def test_2(self): + self.assertEqual(is_palindrome(1), True) + + def test_3(self): + self.assertEqual(is_palindrome(59112), False) + + def test_4(self): + self.assertEqual(is_palindrome(1234554321), True) + + def test_5(self): + self.assertEqual(is_palindrome(22), True) + + def test_6(self): + self.assertEqual(is_palindrome(1010100101), False) + + def test_7(self): + self.assertEqual(is_palindrome(1010110101), True) + + +if __name__ == '__main__': + unittest.main()