fibannatchi
unknown
plain_text
2 years ago
631 B
6
Indexable
# Function to generate Fibonacci sequence up to n terms def generate_fibonacci(n): fibonacci_sequence = [] # Initialize the first two terms a, b = 0, 1 # Generate the Fibonacci sequence for _ in range(n): fibonacci_sequence.append(a) a, b = b, a + b # Update a and b to the next terms return fibonacci_sequence # Number of terms in the sequence n = 100 # Change this to generate a different number of terms # Generate and print the Fibonacci sequence fib_sequence = generate_fibonacci(n) print(f"Fibonacci sequence with {n} terms:") print(fib_sequence)
Editor is loading...