0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377
Fn = F(n-1) + F(n-2)n=15 # number of elements
i=0 # counter
n1=1 # One before
n2=0 # two before
while( i<n):
print(n2, end=', ')
temp=n1+n2
n1=n2
n2=temp
i = i+1
Output
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377,
n1,n2=n2,(n1+n2)
Full code is here
n=15 # number of elements
n1,n2,i=1,0,0 # Setting the values
for i in range( 0,n): #
print(n2, end=', ')
n1,n2=n2,(n1+n2) # change the values
def feb(n):
if(n<=1):
return n
else:
return ((feb(n-1)+feb(n-2)))
for i in range(0,15):
print(feb(i), end=', ')
Output
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377,
# Define a function to generate Fibonacci numbers up to a certain limit
def fibonacci(limit):
a, b = 0, 1 # Initialize the first two Fibonacci numbers
while a < limit: # Continue generating numbers while 'a' is less than the limit
yield a # Yield the current Fibonacci number
a, b = b, a + b # Update 'a' and 'b' to the next Fibonacci numbers
# Create a Fibonacci generator object with numbers up to 100
fib = fibonacci(100)
# Iterate through the generated Fibonacci numbers and print them
for num in fib:
print(num)

Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.