7. Write a Python program to print the Fibonacci series using recursion#2023 #tansche

preview_player
Показать описание
Code in Pinned Comment
Рекомендации по теме
Комментарии
Автор

def fibonacci(n):
if n <= 0:
return []
elif n == 1:
return [0]
elif n == 2:
return [0, 1]
else:
fib_series = fibonacci(n - 1)
+ fib_series[-2])
return fib_series

# Input the number of terms you want in the Fibonacci series
n = int(input("Enter the number of terms: "))

if n <= 0:
print("Please enter a positive integer.")
else:
fib_series = fibonacci(n)
print("Fibonacci Series:")
for num in fib_series:
print(num, end=" ")

dot__com