Write a code to print a Fibonacci series upto the nth term. Use the int(input()) to get an input from the user as well for the value of n.)

Advertisements
Advertisements
Advertisements3
Advertisements4
Advertisements6
Advertisements66
#Write a code to print a Fibonacci series upto the nth term. Use the int(input()) to get an input from the user as well for the value of n.)
x = int(input("enter number of terms in the fibonacci series: "))
def fibonacci1(x):
    n1 = 0
    n2 = 1
    sum1 = 0
    if x <=0:
        print("please enter a number greater than 0")
    else:
        for i in range(0, x):
            print(sum1, end=" ")
            n1 = n2
            n2 = sum1
            sum1 = n1 + n2
fibonacci1(x)

Author: Lakshmi Prasanna Ponnala

Completed M.Tech in Digital Electronics and Communication Systems.

Leave a Reply

error: Content is protected !!

Discover more from ece4uplp

Subscribe now to keep reading and get access to the full archive.

Continue reading