Skip to content

Commit

Permalink
Merge pull request YearOfProgramming#420 from alexbotello/master
Browse files Browse the repository at this point in the history
[Python] Challenge 13 (reviewed and merged)
  • Loading branch information
Steven Landau committed Jan 23, 2017
2 parents 61043f1 + 8fb49b5 commit 84e242c
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
23 changes: 23 additions & 0 deletions challenge_13/python/alexbotello/README.md
Original file line number Diff line number Diff line change
@@ -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
```
21 changes: 21 additions & 0 deletions challenge_13/python/alexbotello/src/palin.py
Original file line number Diff line number Diff line change
@@ -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))
28 changes: 28 additions & 0 deletions challenge_13/python/alexbotello/src/tests.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 84e242c

Please sign in to comment.