-
Notifications
You must be signed in to change notification settings - Fork 6
/
comand_lin.py
34 lines (24 loc) · 993 Bytes
/
comand_lin.py
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
33
34
import argparse
import sys
def calc(args):
if args.o == 'add':
return args.x + args.y
elif args.o == 'mul':
return args.x * args.y
elif args.o == 'sub':
return args.x - args.y
elif args.o == 'div':
return args.x / args.y
else:
return "Something went wrong"
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--x', type=float, default=1.0,
help="Enter first number. This is a utility for calculation. Please contact harry bhai")
parser.add_argument('--y', type=float, default=33.0,
help="Enter second number. This is a utility for calculation. Please contact harry bhai")
parser.add_argument('--o', type=str, default="add",
help="This is a utility for calculation. Please contact harry bhai for more")
# args = parser.parse_args()
args = parser.parse_args()
sys.stdout.write(str(calc(args)))