-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathargparse.py
More file actions
27 lines (21 loc) · 718 Bytes
/
argparse.py
File metadata and controls
27 lines (21 loc) · 718 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
27
import argparse
import sys
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--x',type=float,default=1.0,help='Elige el primeor numero para operar')
parser.add_argument('--y',type=float,default=1.0,help='Elige el segundo numero para operar')
parser.add_argument('--operation',type=str,default='add',help='Elige la operacion')
args=parser.parse_args()
sys.stdout.write(str(calcular(args)))
def calcular(args):
if args.operation == 'add':
resultado = args.x+args.y
if args.operation == 'div':
resultado = args.x/args.y
if args.operation == 'mul':
resultado = args.x*args.y
if args.operation == 'res':
resultado = args.x-args.y
return resultado
if __name__=='__main__':
main()