参考链接
https://blog.csdn.net/qq_41731861/article/details/120827681
import math
import argparse
def parse_args():
parser = argparse.ArgumentParser(description = 'Calculate volume of Cylinder')
parser.add_argument('-r', '--radius',type=int, metavar='', required=True, help='Radius of Cylinder')
parser.add_argument('-H', '--height', type = int, metavar='', required=True,help='Height of Cylinder')
group = parser.add_mutually_exclusive_group()
group.add_argument('-q', '--quiet', action='store_true', help="print quiet")
group.add_argument('-v', '--verbose', action='store_true', help='print verbose')
args = parser.parse_args()
return args
def cylinder_volume(radius, height):
vol = (math.pi) * (radius ** 2)*(height)
return vol
if __name__ == '__main__':
args = parse_args()
volume = cylinder_volume(args.radius, args.height)
if args.quiet:
print(volume)
elif args.verbose:
print("*********volume is %s*******",volume)