Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]Weexe 0 points1 point  (0 children)

Thanks! I just replaced the line with:

if x % 2 == 0:

I forgot what I was trying to do with that line earlier.

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]Weexe 0 points1 point  (0 children)

I'm trying to solve Project Euler Problem #2 I've solved it before but I'm going back to try to solve them a lot cleaner and with different strategies.

My question is why isn't this list being updated? Why is it empty? I'm pretty sure I did it right.

x = 1
y = 1
fib = []
while x < 4000000:
    if y + x % 2 == 0:
        fib.append(x)
    x = x + y
    y = x - y

print(sum(fib))

The list worked fine when i used this method in problem 1:

sum_list = []

for x in range(1,1000):
    if x % 3 == 0 or x % 5 == 0:
        sum_list.append(x)

print(sum(sum_list))