I'm a Sr. Software Engineer at Flashpoint. I specialize in Python and Go, building functional, practical, and maintainable web systems leveraging Kubernetes and the cloud. Blog opinions are my own.
"""Find the sum of even Fibonacci numbers less than 4,000,000"""deffibonacci(cap):"""Generates fibonacci numbers less than cap"""a,b,c=0,1,1whilec<cap:yieldca,b=b,cc=a+bdefeven_fib_sum(cap):"""Returns the sum of even fibonacci numbers less than cap"""returnsum(fibforfibinfibonacci(cap)iffib%2==0)if__name__=="__main__":print(even_fib_sum(4000000))print(list(fibonacci(4000000))# => 4613732# => [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578]
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
4,613,732! :D