Sequenza di Fibonacci Python
def fibonacci(n):
if n<2:
return n
return fibonacci(n-2)+fibonacci(n-1)
print(fibonacci(i))
AleVava
def fibonacci(n):
if n<2:
return n
return fibonacci(n-2)+fibonacci(n-1)
print(fibonacci(i))
def iterativeFibonacci(n):
fibList[0,1]
for i in range(1, n+1):
fibList.append(fibList[i] + fibList[i-1])
return fibList[1:]
########################### Output ##################################
""" E.g. if n = 10, the output is --> [1,1,2,3,5,8,13,21,34,55] """
#Learnprogramo
Number = int(input("How many terms? "))
# first two terms
First_Value, Second_Value = 0, 1
i = 0
if Number <= 0:
print("Please enter a positive integer")
elif Number == 1:
print("Fibonacci sequence upto",Number,":")
print(First_Value)
else:
print("Fibonacci sequence:")
while i < Number:
print(First_Value)
Next = First_Value + Second_Value
# update values
First_Value = Second_Value
Second_Value = Next
i += 1