28 lines
622 B
Python
28 lines
622 B
Python
"""A demo module implementing fib."""
|
|
import argparse
|
|
|
|
|
|
def parse_args():
|
|
"""Parse command line arguments."""
|
|
parser = argparse.ArgumentParser(description="Compute fibonacci sequence numbers.")
|
|
parser.add_argument("n", type=int, help="To compute the nth element of fib.")
|
|
return parser.parse_args()
|
|
|
|
|
|
def fib(n: int) -> int:
|
|
"""Return the *n*th element in the Fibonacci sequence."""
|
|
a, b = 1, 1
|
|
for _ in range(n):
|
|
a, b = b, a + b
|
|
return a
|
|
|
|
|
|
def main() -> None:
|
|
"""The module entry point."""
|
|
args = parse_args()
|
|
print(fib(args.n))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|