def generate_fibonacci_series(n): series = [] if n <= 0: return series elif n == 1: series.append(0) return series else: series = [0, 1] # Starting with the first two terms while len(series) < n: next_term = series[-1] + series[-2] # Generating the next term series.append(next_term) return series # Example usage num_terms = int(input("Enter the number of terms: ")) fibonacci_series = generate_fibonacci_series(num_terms) print("Fibonacci series:") print(fibonacci_series)
Python program to generate the Fibonacci series up to a specified number
0
Tags
Share to other apps