diff options
author | mjfernez <mjfernez@gmail.com> | 2020-02-09 15:16:26 -0500 |
---|---|---|
committer | mjfernez <mjfernez@gmail.com> | 2020-02-09 15:16:26 -0500 |
commit | 93ea7fe5957b62f18e8fbd17a21696bd7de6332d (patch) | |
tree | d90aed60d687bcf195f1150777f37cbe8a149814 /02-Even-Fibonacci-numbers/fib.py | |
parent | 125ec5bc3d8bfc224b7d32bcfbbc37b9fb5d441f (diff) | |
download | Project_Euler_Solutions-93ea7fe5957b62f18e8fbd17a21696bd7de6332d.tar.gz |
Organized everything, update README
Diffstat (limited to '02-Even-Fibonacci-numbers/fib.py')
-rw-r--r-- | 02-Even-Fibonacci-numbers/fib.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/02-Even-Fibonacci-numbers/fib.py b/02-Even-Fibonacci-numbers/fib.py new file mode 100644 index 0000000..c2f2691 --- /dev/null +++ b/02-Even-Fibonacci-numbers/fib.py @@ -0,0 +1,34 @@ +import PIL +import math +MAX = 4*10**6 + +# Problem 2 Even Fibonnacci numbers +fib = [1, 1] + +k = 1 +while (True): + n = fib[k] + fib[k-1] + if(n > MAX): + break + else: + fib.append(n) + k += 1 + +c = 0 +for i in fib: + num = str(i) + print(num + " ", end='') + c += 1 + if(c % 10 == 0): + print() + +print() + +print("The sum is: " + str(sum(fib))) + +s = 0 +for i in fib: + if (i % 2 == 0): + s += i + +print("The sum of the even terms is: " + str(s)) |