def __main__(): print("Hello from main!") LIST_completeFibSequence = [] LIST_evenFibSequence = [] #### nterms = 4000000 nterms = int(input("Calculate the Fibonacci sequence to what max term? ")) #### # Check if the number of terms is valid if nterms <= 0: print("Please enter a positive integer") else: print("Fetching the full sequence...") for i in range(nterms): LIST_completeFibSequence.append(recursive_fibonacci(i)) LIST_evenFibSequence = remove_odd_ints_from_list(LIST_completeFibSequence) #print("List of all even Fibonacci sequence values within specified range: " + str(LIST_evenFibSequence)) evenFibSum = sum(LIST_evenFibSequence) print("Sum of all even Fibonacci sequence values within specified range: " + str(evenFibSum)) #Recursive function to print Fibonacci sequence def recursive_fibonacci(n): if n <= 1: return n else: return(recursive_fibonacci(n-1) + recursive_fibonacci(n-2)) def remove_odd_ints_from_list(LIST_passedInts): print("Hello from removeOdds!") return [x for x in LIST_passedInts if x % 2 == 0] __main__()
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