forked from codeperfectplus/Pythonite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathargparse.py
More file actions
26 lines (23 loc) · 835 Bytes
/
Copy pathargparse.py
File metadata and controls
26 lines (23 loc) · 835 Bytes
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
import argparse
import sys
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--x', type=float, default=1.0,
help='What is the first number?')
parser.add_argument('--y', type=float, default=1.0,
help='What is the second number?')
parser.add_argument('--operation', type=str, default='add',
help='What operation? Can choose add, sub, mul, or div')
args = parser.parse_args()
sys.stdout.write(str(calc(args)))
def calc(args):
if args.operation == 'add':
return args.x + args.y
elif args.operation == 'sub':
return args.x - args.y
elif args.operation == 'mul':
return args.x * args.y
elif args.operation == 'div':
return args.x / args.y
if __name__ == '__main__':
main()