“Fibonacci Sequence Python Code” Réponses codées

fibonacci python

# Implement the fibonacci sequence
	# (0, 1, 1, 2, 3, 5, 8, 13, etc...)
	def fib(n):
		if n== 0 or n== 1:
			return n
		return fib (n- 1) + fib (n- 2) 
Clean Cowfish

séquence fibonacci python

# WARNING: this program assumes the
# fibonacci sequence starts at 1
def fib(num):
  """return the number at index num in the fibonacci sequence"""
  if num <= 2:
    return 1
  return fib(num - 1) + fib(num - 2)


print(fib(6))  # 8
Blue-eyed Barracuda

séquence fibonacci python

num = 1
num1 = 0
num2 = 1
import time
for i in range(0, 10):
    print(num)
    num = num1 + num2
    num1 = num2
    num2 = num
    time.sleep(1)
Henry Bass

Fibonacci Sequence Python Code

#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
Gleaming Grasshopper

Réponses similaires à “Fibonacci Sequence Python Code”

Questions similaires à “Fibonacci Sequence Python Code”

Plus de réponses similaires à “Fibonacci Sequence Python Code” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code