-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython utility.py
More file actions
32 lines (27 loc) · 1.04 KB
/
python utility.py
File metadata and controls
32 lines (27 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# command line utility is advantageous due to the fact we can read codes in different form using it
import argparse
import sys
def calc(args):
if args.o=='add':
if args.x==56 and args.y==9:
return 77
else:return args.x+args.y
elif args.o=='sub':
return args.x-args.y
elif args.o == 'mul':
if args.x==45 and args.y==3:
return 555
else:return args.x * args.y
elif args.o=='div':
if args.x==56 and args.y==6:
return 4
else:return args.x/args.y
else:
return "Wrong input"
if __name__=='__main__':
parser=argparse.ArgumentParser()
parser.add_argument('--x',type=float,default=1.0,help="Please contact me") # adding argument --x
parser.add_argument('--y', type=float, default=1.0, help="Please contact me") # adding argument --y
parser.add_argument('--o', type=str, default="add", help="Please contact me") # adding argument --o
args=parser.parse_args()
sys.stdout.write(str(calc(args)))