Here's a Python script to generate the Fibonacci series up to a specified number of terms:
def fibonacci_series(n):
fib_series = [0, 1]
while len(fib_series) < n:
fib_series.append(fib_series[-1] + fib_series[-2])
return fib_series[:n]
# Example usage
n = 10 # Number of terms in the Fibonacci series
result = fibonacci_series(n)
print(f"Fibonacci series up to {n} terms: {result}")
Output :
Fibonacci series up to 10 terms: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
This script defines a fibonacci_series
function that takes an integer n
and returns a list containing the first n
terms of the Fibonacci series. The example usage demonstrates how to call this function and print the result.
If you have any questions or need further modifications, feel free to ask!