skip420

squared_Calucation

Jan 25th, 2021
532
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import argparse
  2. import sys
  3.  
  4. try:
  5.      parser = argparse.ArgumentParser()
  6.      parser.add_argument("square", help="display a square of a given number",
  7.                 type=int)
  8.      args = parser.parse_args()
  9.  
  10.     #print the square of user input from cmd line.
  11.      print args.square**2
  12.  
  13.     #print all the sys argument passed from cmd line including the program name.
  14.      print sys.argv
  15.  
  16.     #print the second argument passed from cmd line; Note it starts from ZERO
  17.      print sys.argv[1]
  18. except:
  19.     e = sys.exc_info()[0]
  20.     print e
RAW Paste Data