aboutsummaryrefslogtreecommitdiffstats
path: root/fib.py
diff options
context:
space:
mode:
authormjfernez <mjfernez@gmail.com>2020-02-03 23:04:10 -0500
committermjfernez <mjfernez@gmail.com>2020-02-03 23:04:10 -0500
commit8e431d287c0e89041506da4c4da57e3e3d657d72 (patch)
treeb6cd296fbdd75d1421fe84a82cf3eec859407dcb /fib.py
parente6a7399134b3dc08f9e6e9c9c74e39ac449b8538 (diff)
downloadProject_Euler_Solutions-8e431d287c0e89041506da4c4da57e3e3d657d72.tar.gz
cleanup, added c translations for some
Diffstat (limited to 'fib.py')
-rw-r--r--fib.py39
1 files changed, 20 insertions, 19 deletions
diff --git a/fib.py b/fib.py
index 77b32fa..c2f2691 100644
--- a/fib.py
+++ b/fib.py
@@ -1,33 +1,34 @@
-import PIL, math
+import PIL
+import math
MAX = 4*10**6
-#Problem 2 Even Fibonnacci numbers
+# Problem 2 Even Fibonnacci numbers
fib = [1, 1]
-k=1;
+k = 1
while (True):
- n = fib[k] + fib[k-1]
- if(n>MAX):
- break
- else:
- fib.append(n);
- k+=1
+ n = fib[k] + fib[k-1]
+ if(n > MAX):
+ break
+ else:
+ fib.append(n)
+ k += 1
-c=0
+c = 0
for i in fib:
- num = str(i)
- print(num + " ", end='')
- c+=1
- if(c%10==0):
- print()
-
+ num = str(i)
+ print(num + " ", end='')
+ c += 1
+ if(c % 10 == 0):
+ print()
+
print()
print("The sum is: " + str(sum(fib)))
-s=0
+s = 0
for i in fib:
- if (i%2==0):
- s+=i
+ if (i % 2 == 0):
+ s += i
print("The sum of the even terms is: " + str(s))