-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem2.py
More file actions
34 lines (27 loc) · 768 Bytes
/
problem2.py
File metadata and controls
34 lines (27 loc) · 768 Bytes
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
34
def find_sum_of_even_values(sequence):
total = 0
for x in sequence:
if x % 2 == 0:
total += x
return total
def next_fibonacci_number(current, previous):
return current + previous
def generate_fibonacci_sequence(upper_limit):
sequence = [0, 1]
previous = 0
current = 1
while True:
new_value = next_fibonacci_number(current, previous)
if new_value > upper_limit:
return sequence
previous = current
current = new_value
sequence.append(current)
seq = generate_fibonacci_sequence(100)
print(seq)
even_sum = find_sum_of_even_values(seq)
print(even_sum)
seq = generate_fibonacci_sequence(4000000)
print(seq)
even_sum = find_sum_of_even_values(seq)
print(even_sum)