From e1d76dd1d6e9cd35a17e6443d7222a9499ccc698 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Sun, 23 Apr 2017 19:43:32 +0200 Subject: Update lswf.py --- lswf.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lswf.py b/lswf.py index 29d58b2..cc51cb7 100644 --- a/lswf.py +++ b/lswf.py @@ -1,23 +1,20 @@ fib = [1, 1] -lst = 0 def fibonacci(N): - global lst for i in range(2, N): fib.append(fib[i - 1] + fib[i - 2]) - lst = i + if fib[i] > N: break + + return i with open('input.txt', 'r') as fin: N = int(fin.readline()) -fibonacci(N) - -for i in fib: - print(i, end=' ') +lst = fibonacci(N) fib.reverse() print() @@ -40,4 +37,4 @@ if N == 1 or N > 4: with open('output.txt', 'w') as fout: for i in seq: - fout.write(str(i)) \ No newline at end of file + fout.write(str(i)) -- cgit v1.2.3-18-g5258