def fibonacci_series(n): fib_sequence = [0, 1] # Starting values for Fibonacci series while len(fib_sequence) < n: # Add the last two numbers to get the next one next_number = fib_sequence[-1] + fib_sequence[-2] fib_sequence.append(next_number) return fib_sequence[:n] # Return only first 'n' elements # Example usage num_terms = int(input("Enter the number of terms: ")) print("Fibonacci Series:") print(fibonacci_series(num_terms))
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter