From 1d29e990e7a8a2a0f18a96d4e92c3ccfbf06da75 Mon Sep 17 00:00:00 2001 From: VritangiKansal Date: Tue, 27 Sep 2022 14:07:20 -0400 Subject: [PATCH] learning arg --- 06_argparser/submissions/kansal17.py | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 06_argparser/submissions/kansal17.py diff --git a/06_argparser/submissions/kansal17.py b/06_argparser/submissions/kansal17.py new file mode 100644 index 0000000..38a2227 --- /dev/null +++ b/06_argparser/submissions/kansal17.py @@ -0,0 +1,37 @@ +import numpy as np + + +def afunc(array1, array2, mode="+", pow=2): + assert array1.shape == array2.shape, "size mismatch" + assert type(pow) == int, "pow should be type int" + + if mode == "+": + result = array1 + array2 + elif mode == "-": + result = array1 - array2 + else: + raise ValueError(f"mode is either '+' or '-' but got {mode}") + + result = result ** pow + return result + + +if __name__ == "__main__": + import argparse + + parser = argparse.ArgumentParser(description="This is tutorial for argparse.") # noqa: E501 + # add your code here + parser.add_argument('mode', metavar='mode', type=str, help='a mode string', default='+') # noqa: E501 + parser.add_argument('pow', metavar='pow', type=int, help='an int pow', default=2) # noqa: E501 + parser.add_argument('print_hello', action='store_true') + + # add your code here + args = parser.parse_args() + print(args) + + a = np.array([1, 2, 3]) + b = np.array([4, 5, 6]) + result = afunc(a, b, args.mode, args.pow) + print(result) + if args.print_hello: + print("Hello!") \ No newline at end of file