From 0e77ec5ae168f13efa7cf51e7d2bb124ce3002d0 Mon Sep 17 00:00:00 2001 From: itec78 Date: Mon, 31 Aug 2020 18:21:24 +0200 Subject: [PATCH] Fixed defaults --- banana.py | 15 +++++++++++++-- banana2dec.py | 6 +++--- dec2ananas.py | 2 +- dec2banana.py | 8 ++++---- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/banana.py b/banana.py index 102ab64..9c60a9d 100755 --- a/banana.py +++ b/banana.py @@ -1,6 +1,12 @@ #!/usr/bin/env python3 -def dec2banana(num, dictstart = 0, shiftend = 0, minlength = 0, dictionary = [list("bcdfglmnprstvz"), list("aeiou")]): +def dec2banana(num, dictstart = None, shiftend = None, minlength = None, dictionary = None): + #defaults + if dictstart is None: dictstart = 0 + if shiftend is None: shiftend = 0 + if minlength is None: minlength = 0 + if dictionary is None: dictionary = [list("bcdfglmnprstvz"), list("aeiou")] + numdict = len(dictionary) v = num st = "" @@ -17,7 +23,12 @@ def dec2banana(num, dictstart = 0, shiftend = 0, minlength = 0, dictionary = [li return(st) -def banana2dec(banana, dictstart = 0, shiftend = 0, dictionary = [list("bcdfglmnprstvz"), list("aeiou")] ): +def banana2dec(banana, dictstart = None, shiftend = None, dictionary = None): + #defaults + if dictstart is None: dictstart = 0 + if shiftend is None: shiftend = 0 + if dictionary is None: dictionary = [list("bcdfglmnprstvz"), list("aeiou")] #, list("123456") + numdict = len(dictionary) v = 0 for i in range(len(banana)): diff --git a/banana2dec.py b/banana2dec.py index a6611c5..840c887 100755 --- a/banana2dec.py +++ b/banana2dec.py @@ -5,9 +5,9 @@ import banana if __name__ == "__main__": parser = argparse.ArgumentParser(description="Convert banana string to dec") parser.add_argument("banana", help="String to be converted") - parser.add_argument("--dictionary", help="Set dictionary", type=list, nargs='+', default=[list("bcdfglmnprstvz"), list("aeiou")]) # , list("123456") - parser.add_argument("--dictstart", help="Set starting dictionary", type=int, default=0) - parser.add_argument("--shiftend", help="Set shift for ending dictionary", type=int, default=0) + parser.add_argument("--dictionary", help="Set dictionary", type=list, nargs='+') + parser.add_argument("--dictstart", help="Set starting dictionary", type=int) + parser.add_argument("--shiftend", help="Set shift for ending dictionary", type=int) args = parser.parse_args() print(banana.banana2dec(args.banana, args.dictstart, args.shiftend, args.dictionary)) diff --git a/dec2ananas.py b/dec2ananas.py index 275d2fd..8406766 100755 --- a/dec2ananas.py +++ b/dec2ananas.py @@ -5,7 +5,7 @@ import banana if __name__ == "__main__": parser = argparse.ArgumentParser(description="Convert dec number to banana") parser.add_argument("num", help="number to be converted", type=int) - parser.add_argument("--minlength", help="Set minimum length", type=int, default=0) + parser.add_argument("--minlength", help="Set minimum length", type=int) args = parser.parse_args() print(banana.dec2banana(args.num, 1, 0, args.minlength)) diff --git a/dec2banana.py b/dec2banana.py index 03314eb..19681cc 100755 --- a/dec2banana.py +++ b/dec2banana.py @@ -5,10 +5,10 @@ import banana if __name__ == "__main__": parser = argparse.ArgumentParser(description="Convert dec number to banana") parser.add_argument("num", help="number to be converted", type=int) - parser.add_argument("--dictstart", help="Set starting dictionary", type=int, default=0) - parser.add_argument("--shiftend", help="Set shift for ending dictionary", type=int, default=0) - parser.add_argument("--minlength", help="Set minimum length", type=int, default=0) - parser.add_argument("--dictionary", help="Set dictionary", type=list, nargs='+', default=[list("bcdfglmnprstvz"), list("aeiou")]) # , list("123456") + parser.add_argument("--dictstart", help="Set starting dictionary", type=int) + parser.add_argument("--shiftend", help="Set shift for ending dictionary", type=int) + parser.add_argument("--minlength", help="Set minimum length", type=int) + parser.add_argument("--dictionary", help="Set dictionary", type=list, nargs='+') args = parser.parse_args() print(banana.dec2banana(args.num, args.dictstart, args.shiftend, args.minlength, args.dictionary))