Commit 124d425d7fe8419036e98abd0c9eb6375dc93d61
1 parent
ce3cdc5edc
Exists in
master
b0474d3c-36c0-4caa-9307-1155648ed90c
Showing 3 changed files with 16 additions and 23 deletions
README.md
View file @
124d425
... | ... | @@ -37,7 +37,6 @@ |
37 | 37 | 5b745b2c7897c0c07bd33d7467adb837588bd412d4eea107b758586e2c0522b2 fibonacci.php |
38 | 38 | 2b917506ec9732c1272df4345a16bfecd0dce54754fd7c40eb7830a3653a4818 fibonacci.php.asc |
39 | 39 | d41722d8fb508f584b063d7bf0e8d1c19a119d62deba46245f8afdd4766ef391 fibonacci.py |
40 | -07ef45ae9fb104c64f9a150c0fadd8c99068f191c80378b415b1f1531ac70812 fibonacci.py.asc | |
41 | 40 | 560b6b2b3446cb7c7fd26f6576d4e469890791dbb94db9254f446c9e304c50f3 fibonacci.sh |
42 | 41 | d91fac27b81d7fc938281630ee405f75da3a6869e6e95955e7ea7bc756dce939 fibonacci.sh.asc |
43 | 42 |
fibonacci.py
View file @
124d425
1 | 1 | #!/usr/bin/env python3 |
2 | 2 | # -*- coding: utf-8 -*- |
3 | 3 | |
4 | -import sys | |
4 | +import sys, argparse | |
5 | 5 | |
6 | -if len(sys.argv) == 1 or not sys.argv[1].isnumeric() or int(sys.argv[1]) <= 0: | |
7 | - msg = """\ | |
8 | -Usage: {:s} nbr_int | |
9 | - nbr_int: Un nombre entier supérieur à 0""".format(sys.argv[0]) | |
10 | - print(msg) | |
6 | +parser = argparse.ArgumentParser(description=u"Calcul et affiche les n premiers nombres de la suite de Fibonacci.") | |
7 | +parser.add_argument("number", help=u"Nombre maximum de calcul de la séquence. Ce nombre doit égal ou supérieur à 2.", type=int) | |
8 | +parser.add_argument("-g", "--display-golden-number", dest="golden", help=u"Afficher le nombre d'or.", action="store_true") | |
9 | +parser.add_argument("--log", default=sys.stdout, type=argparse.FileType('w'), help=u"Fichier où sera enregistré le résultat.") | |
10 | +args = parser.parse_args() | |
11 | + | |
12 | +if args.number < 2: | |
13 | + print(u"Indiquer un nombre supérieur ou égal à 2.") | |
11 | 14 | sys.exit(1) |
12 | 15 | |
13 | 16 | a,b = 0,1 |
14 | 17 | |
15 | -while b < int(sys.argv[1]): | |
16 | - print(b) | |
18 | +while b < args.number: | |
19 | + print("{:d}".format(b), file=args.log) | |
17 | 20 | a,b = b,a+b |
18 | 21 | |
19 | -print("b/a = {:1.15f}".format(b/a)) | |
22 | +if args.golden: | |
23 | + print(u"\nb/a = {:1.15f} (Nombre d'or)".format(b/a), file=args.log) | |
20 | 24 | |
25 | +args.log.close() | |
21 | 26 | sys.exit(0) |
fibonacci.py.asc
View file @
124d425
1 | ------BEGIN PGP SIGNATURE----- | |
2 | -Version: GnuPG v1 | |
3 | - | |
4 | -iQEcBAABAgAGBQJV7UwfAAoJEIgCKezOqEu6U1AH/1qPD0oQcgdl2wpo6M3ZAaFM | |
5 | -0VlYQ34PhDKlYwJIF/yl8/4FdZl9hMOwnSfboUgpIcqeHYOQwwRODrerYVpf2iOA | |
6 | -zr2/dCNwDviRaG9jP3cZySWnfwgK2y9wS6/6jj/G3sewAV6dETJ+fsz6Fu8hdZkf | |
7 | -KSHhZbhVZQnB5hVUs2/8UL5NzoNCz1glCjrRYDSVLE3+qkGRPIFFOHSVJdGJzgOn | |
8 | -jCjkH2efX0Y7tl3Mf7MdTZ5auwlzLIo3/vawbkWI+aTInexWdxAy5MSlT8EcyvHG | |
9 | -Rz0BdVnduYcM/7wJXrxyvisCSZgCnT3PNw6nrDyeVM5TCwrvYilsMt0ncEp5bck= | |
10 | -=AaPa | |
11 | ------END PGP SIGNATURE----- |