Menu Close

Problem 2

My solution, in Python:

print("How many values would you like to find?")
endVal = int(input())
fib1 = 1
fib2 = 2
fib = [fib1,fib2] 
for num in range(1, endVal):
    temp = fib1 + fib2
    if(temp <= 4000000):
        fib.append(temp)
        fib1 = fib2
        fib2 = temp
print(fib)

def sumEvens(seq):
    tot = 0
    for i in range(1, len(seq)):
        if (seq[i] % 2 == 0):
            tot = tot + seq[i]
    return tot

print(sumEvens(fib))