aboutsummaryrefslogtreecommitdiffstats
path: root/fib.py
blob: 77b32fa300f79ec68585c79326e0c0f6d8c0337e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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))