Advertisement
furas

Python - correct indention

Apr 14th, 2017
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. import argparse
  2. import sys
  3.  
  4. def main1():
  5.     parser = argparse.ArgumentParser()
  6.     parser.add_argument('--x', type = float , default = 1.0,
  7.     help = 'Enter the first num')
  8.     parser.add_argument('--y', type = float , default = 1.0 ,
  9.     help = 'Enter the second num')
  10.     parser.add_argument('--operation', type = str, default = 'add',
  11.     help = 'specify the type of operation(add,sub,div,mul)')
  12.     args = parser.parse_args()
  13.     sys.stdout.write(str(calc(args)))
  14.  
  15. def calc(args):
  16.     if args.operation == 'add':
  17.         return args.x + args.y
  18.     elif args.operation == 'mul':
  19.         return args.x * args.y
  20.     elif args.operation == 'div':
  21.         return args.x / args.y
  22.     elif args.operation =='sub':
  23.         return args.x - args.y
  24.  
  25. main1() # <-- without indention
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement