fibonacci

Fibonacci Sequence based question slightly changed

Fibonacci Sequence based question slightly changed Question: I was recently given this question in one of my interview which I ofcourse, failed. I just want to know how this will be solved. The code I tried to use was this: def gibonacci(n, x, y): # Base case if n == 0: return x elif n …

Total answers: 2

Implementing the Fibonacci sequence for the last n elements: The nBonacci sequence

Implementing the Fibonacci sequence for the last n elements: The nBonacci sequence Question: I was curious about how I can implement the Fibonacci sequence for summing the last n elements instead of just the last 2. So I was thinking about implementing a function nBonacci(n,m) where n is the number of last elements we gotta …

Total answers: 3

How do I get the last number in a list that is very large?

How do I get the last number in a list that is very large? Question: def fib(n): a=0 b=1 for i in range(n+1): yield a a,b = b,a+b lastnum = [num for num in fib(150000)] lastnum[-1] This is about the largest number (150000th number in fib) I can get from this method (Memory Error if …

Total answers: 1

Return Parameters from a Recursive function in python

Return Parameters from a Recursive function in python Question: sorry if this is a noob question, I wasn’t able to find a solution online (maybe I just don’t know what to search for). How do I return the "found" dictionary from this recursive function (I am only able to return the nth number) Note: simply …

Total answers: 2

Python: Sum Of The Final Two Numbers In A List, Then Append

Python: Sum Of The Final Two Numbers In A List, Then Append Question: For example lets say my input is 12, I am attempting to get the output of the lucas sequence to be [2 1 3 4 7 11], but instead I keep receiving the output of [2, 1, 3, 4, 7, 11, 18, …

Total answers: 2

Fibonacci Measurement Algorithm implementation: missing 1 required positional argument: 'p'

Fibonacci Measurement Algorithm implementation: missing 1 required positional argument: 'p' Question: I’ve implemented a fibonacci Measurement algorithm with 2 parameter n and p. I got this issue, TypeError Traceback (most recent call last) <ipython-input-19-295638b26e62> in <module> 2 N = 10 3 # [F(n,p) for n in range(N)] —-> 4 print(F(10,1)) <ipython-input-12-fda62c8ec9a6> in F(n, p) 6 …

Total answers: 1

difference between these two fibonacci python code

difference between these two fibonacci python code Question: What is the difference between these two python code?.i thought both are same but the output i am getting is different def fibonacci(num): a=1 b=1 series=[] series.append(a) series.append(b) for i in range(1,num-1): series.append(a+b) #a,b=b,a+b a=b b=a+b return series print(fibonacci(10)) def fibonacci(num): a=1 b=1 series=[] series.append(a) series.append(b) for …

Total answers: 2

fixing Fibonacci numbers from a range of 1 to 50 Python

fixing Fibonacci numbers from a range of 1 to 50 Python Question: I have a set of numbers from 1 to 50 and from these numbers I have to find which are Fibonacci number, after that I have to find which of these numbers contain the number 1 and 2. For example in my code …

Total answers: 1