palindrome/palindrome.py
2021-03-23 14:46:08 +01:00

42 lines
1.4 KiB
Python
Executable File

#!/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',
'--integer',
required=True,
help='The integer to be transformed.',
type=int)
# NOTE: The argument must be an integer. Because of this constrain integers
# with leading zeroes will be stripped automatically in python 3. Also the
# script only allows integers as an input defined by type=int
args = parser.parse_args()
return args
def main():
args = parse_args()
if args.integer <= 10000 and args.integer > 0:
print('Input integer is: {}'.format(args.integer))
transform = Transform()
palindrome = transform.palindrome(args.integer)
if palindrome == transform.INVALID_RETURN_VALUE:
print('Palindrome to be calculated is to big. Abort!')
print("Final Output is:", palindrome)
return palindrome
else:
print("Input integer is not betweent 1 and 10000")
if __name__ == '__main__':
main()