Header Ads

Header ADS

practical no:3:the fibonacci sequence is the series of numbers 0,1,2,3,3,5,8....formally,it can be expressed as :fifo=0,fib1,fib=fib n-1+fib n-2.Write a multithread program that generates the fibonacci sequence.

 #the fibonacci sequence is the series of numbers 0,1,2,3,3,5,8....formally,it can be expressed as :fifo=0,fib1,fib=fib n-1+fib n-2.Write a multithread program that generates the fibonacci sequence.

import threading

def print_fibbo():

    nterms=int(input("how many terms :"))

    n1,n2=0,1

    count=0

    if nterms<=0:

     print("please ender a positive integer:")

    elif nterms==1:

        print("fibonacci sequence upto",nterms,":")

        print(n1)

    else:

        print("fibonacci sequence:")

        while count<nterms:

            print(n1)

            nth=n1+n2

            n1=n2

            n2=nth

            count +=1

if __name__=="__main__":

    t1=threading.Thread(target=print_fibbo)

    t1.start()

    t1.join()

    print("done")


No comments

Powered by Blogger.