palindrome/palindrome.py

42 lines
1.4 KiB
Python
Raw Normal View History

2021-03-17 09:32:45 +00:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
from transform.Transform import Transform
def parse_args():
'''
Argument Parser for terminal usage.
'''
parser = argparse.ArgumentParser(description=('Throw in an integer N to'
'transform it into a'
'palindrome'))
parser.add_argument('-i',
2021-03-17 13:25:22 +00:00
'--integer',
2021-03-17 09:32:45 +00:00
required=True,
help='The integer to be transformed.',
type=int)
2021-03-17 11:37:54 +00:00
# NOTE: The argument must be an integer. Because of this constrain integers
2021-03-17 13:25:22 +00:00
# with leading zeroes will be stripped automatically in python 3. Also the
# script only allows integers as an input defined by type=int
2021-03-17 09:32:45 +00:00
args = parser.parse_args()
return args
def main():
args = parse_args()
2021-03-17 13:25:22 +00:00
if args.integer <= 10000 and args.integer > 0:
print('Input integer is: {}'.format(args.integer))
2021-03-17 11:37:54 +00:00
transform = Transform()
2021-03-17 13:25:22 +00:00
palindrome = transform.palindrome(args.integer)
if palindrome == transform.INVALID_RETURN_VALUE:
print('Palindrome to be calculated is to big. Abort!')
2021-03-17 11:37:54 +00:00
print("Final Output is:", palindrome)
return palindrome
else:
print("Input integer is not betweent 1 and 10000")
2021-03-17 09:32:45 +00:00
if __name__ == '__main__':
main()