forked from david-parsons/tp-git-intro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runsphere
executable file
·34 lines (32 loc) · 1.41 KB
/
runsphere
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
28
29
30
31
32
33
34
#!/usr/bin/env python3
from sphere import sphere
import argparse
if __name__ == "__main__":
optparser = argparse.ArgumentParser(description='Sphere properties computation')
optparser.add_argument('radius', type=float, nargs='?', default=None, help='Sphere radius')
optparser.add_argument('-v', action='store_true', help='get volume')
optparser.add_argument('-s', action='store_true', help='get surface')
optparser.add_argument('-d', action='store_true', help='get diameter')
optparser.add_argument('--load', help='load from file')
optparser.add_argument('--save', help='save to file')
opts = optparser.parse_args()
if opts.radius == None and opts.load == None:
optparser.error("you must supply a radius")
if opts.radius and opts.load:
optparser.error("you must not supply a radius when loading from file")
if opts.load:
print("loading Sphere from from file %s" % opts.load)
my_sphere = sphere.loadSphere(opts.load)
else:
my_sphere = sphere.Sphere(opts.radius)
print("%s" % my_sphere)
print(" radius is %s" % my_sphere.radius)
if opts.v:
print(" volume is %s" % my_sphere.volume())
if opts.s:
print(" surface is %s" % my_sphere.surface())
if opts.d:
print(" diameter is %s" % my_sphere.diameter())
if opts.save:
print("dumping Sphere to file %s" % opts.save)
my_sphere.dump(opts.save)