From a579b51489651702990dc670f0999b18fc25e54b Mon Sep 17 00:00:00 2001 From: Saketh Karumuri Date: Thu, 4 Aug 2022 19:55:44 -0700 Subject: [PATCH 1/2] Added the base code for the calculator --- calculator.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 calculator.py diff --git a/calculator.py b/calculator.py new file mode 100644 index 0000000..93e7288 --- /dev/null +++ b/calculator.py @@ -0,0 +1,35 @@ +from argparse import ArgumentError +import sys + +def add(x, y): + pass + +def sub(x, y): + pass + +def mult(x, y): + pass + +def div(x, y): + pass + +if __name__ == '__main__': + if len(sys.argv) != 3: + raise ArgumentError("Incorrect Number of Arguments") + + x = sys.argv[1] + y = sys.argv[2] + + if sys.argv[0].lower() == "add": + print(add(x, y)) + + elif sys.argv[0].lower() == "sub": + print(sub(x, y)) + + elif sys.argv[0].lower() == "mult": + print(mult(x, y)) + + elif sys.argv[0].lower() == "div": + print(div(x, y)) + + else: raise ArgumentError("Invalid Operation") \ No newline at end of file From 56c00066ea8aee92c87cd010a2469527f1fd51c8 Mon Sep 17 00:00:00 2001 From: Amanda Lieng Date: Mon, 8 Aug 2022 09:23:24 -0700 Subject: [PATCH 2/2] add addition functionality --- calculator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/calculator.py b/calculator.py index 93e7288..b1523d4 100644 --- a/calculator.py +++ b/calculator.py @@ -2,7 +2,7 @@ import sys def add(x, y): - pass + return x+y def sub(x, y): pass