def problem2(limit): arr, totalEven, term1, term2 = [], 0, 0, 0 while term1 + term2 < limit: if arr.__len__() > 2 : term1, term2 = arr[-1], arr[-2] newVal = term1 + term2 arr.append(newVal) term1, term2 = arr[-1], arr[-2] else: arr.append(arr.__len__() + 1) for y in arr: if y % 2 == 0 : totalEven += y return totalEven print problem2(4000000)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question