top of page

Python Program To Generate Tribonacci Series

realcode4you

In this program we have generate series by taking input from user. In this number is the sum of previous three number


For Example:

Input :

6

Output:

1 1 1 3 5 9


Input :

7

Output:

1 1 1 3 5 9 17



Program

#Function to print the series
def Rec(n) :
    #Check number and return 1 at zero index positon
    if(n==0):
        return 1
    #Check number and return 1 at one index positon
    elif(n==1):
        return 1
    #Check number and return 1 at second index positon
    elif(n==2):
        return 1
    #Check number and return 1 at Third index positon
    elif(n==3):
        return 1
    #Check number and return 3 at fourth index positon
    elif(n==4):
        return 3
    #If number is greater then 4 then it return sum of previous three numbers
    else :
        return (Rec(n - 1) +
                Rec(n - 2) +
                Rec(n - 3))

#Driver Code
#Take the input from user
n = int(input("Enter the number \n"))
#For Loop which used to print the series upto n+1
for i in range(1, n+1) :
    print( Rec(i) , " ", end = "")

Comments


REALCODE4YOU

Realcode4you is the one of the best website where you can get all computer science and mathematics related help, we are offering python project help, java project help, Machine learning project help, and other programming language help i.e., C, C++, Data Structure, PHP, ReactJs, NodeJs, React Native and also providing all databases related help.

​

Hire Us to get Instant help from realcode4you expert with an affordable price.

USEFUL LINKS

Discount

ADDRESS

Noida, Sector 63, India 201301

Follows Us!

  • Facebook
  • Twitter
  • Instagram
  • LinkedIn

OUR CLIENTS BELONGS TO

  • india
  • australia
  • canada
  • hong-kong
  • ireland
  • jordan
  • malaysia
  • new-zealand
  • oman
  • qatar
  • saudi-arabia
  • singapore
  • south-africa
  • uae
  • uk
  • usa

© 2023 IT Services provided by Realcode4you.com

bottom of page