Answers for "tribonacci sequence python"

5

how to create fibonacci sequence in python

#Python program to generate Fibonacci series until 'n' value
n = int(input("Enter the value of 'n': "))
a = 0
b = 1
sum = 0
count = 1
print("Fibonacci Series: ", end = " ")
while(count <= n):
  print(sum, end = " ")
  count += 1
  a = b
  b = sum
  sum = a + b
Posted by: Guest on May-21-2020
2

fibonacci sequence 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
Posted by: Guest on April-10-2020
0

iterative tribonacci python

def trib_iter(m):
    lista=[m]
    c=0
    d=True
    while d==True:
        novalista=[]
        for n in lista:
            if n in [0,1,2]:
                c+=1
            else:
                for i in range(1,4):
                    if n-i in [0,1,2]:
                        c+=1
                    else:
                        if n-i<0:
                            pass
                        else:
                            novalista.append(n-i)
        if novalista==[]:
            d=False
        else:
            lista=novalista
    return c
Posted by: Guest on June-21-2020

Python Answers by Framework

Browse Popular Code Answers by Language