Fibonacci example (imperative)
This commit is contained in:
parent
b07b6827ba
commit
bf94a2b282
1 changed files with 20 additions and 0 deletions
20
fibonacci.py
Executable file
20
fibonacci.py
Executable file
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
|
||||
def F(n):
|
||||
a = 0
|
||||
b = 1
|
||||
while n > 0:
|
||||
c = a
|
||||
a = a + b
|
||||
b = c
|
||||
n = n - 1
|
||||
return a
|
||||
|
||||
def main():
|
||||
for arg in sys.argv[1:]:
|
||||
print("F(" + arg + "): " + str(F(int(arg))))
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Reference in a new issue