-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfib_argparse.py
More file actions
37 lines (28 loc) · 936 Bytes
/
Copy pathfib_argparse.py
File metadata and controls
37 lines (28 loc) · 936 Bytes
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
35
36
import argparse
def fib(n):
a, b = 0,1
for i in range(n):
a, b = b, a+b
return a
def Main():
parser = argparse.ArgumentParser()
group = parser.add_mutually_exclusive_group()
group.add_argument("-v", "--verbose", action="store_true")
group.add_argument("-q", "--quiet", action="store_true")
parser.add_argument("num", help=" The fibonacci seereses you want \
to calculate", type=int)
parser.add_argument("-o", "--output", help="This is for output",\
action="store_true")
args = parser.parse_args()
result = fib(args.num)
if args.verbose:
print("The "+str(args.num)+"the fib number is "+str(result))
elif args.quiet:
print(result)
else:
print("Fib("+str(args.num)+") = "+str(result)+"")
if args.output:
f = open("abc.txt", "a")
f.write(str(result)+'\n')
if __name__ == '__main__':
Main()