Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import argparse
- import sys
- def main1():
- parser = argparse.ArgumentParser()
- parser.add_argument('--x', type = float , default = 1.0,
- help = 'Enter the first num')
- parser.add_argument('--y', type = float , default = 1.0 ,
- help = 'Enter the second num')
- parser.add_argument('--operation', type = str, default = 'add',
- help = 'specify the type of operation(add,sub,div,mul)')
- 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 == 'mul':
- return args.x * args.y
- elif args.operation == 'div':
- return args.x / args.y
- elif args.operation =='sub':
- return args.x - args.y
- main1() # <-- without indention
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement