aboutsummaryrefslogtreecommitdiffstats
path: root/fib.py
diff options
context:
space:
mode:
authormjfernez <mjfernez@gmail.com>2018-12-02 19:12:42 -0500
committermjfernez <mjfernez@gmail.com>2018-12-02 19:12:42 -0500
commitd62ba829dc3a54edc46b7deb581dd244713393f5 (patch)
tree637d985d70fff70c4dedc14a45c559747ea18b84 /fib.py
parentc15221f10ed2ea4a55b474a57b6ee39f6b24ac85 (diff)
downloadProject_Euler_Solutions-d62ba829dc3a54edc46b7deb581dd244713393f5.tar.gz
add code
Diffstat (limited to 'fib.py')
-rw-r--r--fib.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/fib.py b/fib.py
new file mode 100644
index 0000000..77b32fa
--- /dev/null
+++ b/fib.py
@@ -0,0 +1,33 @@
+import PIL, 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))