gpt-4-1106-preview· openai
Suzhen/CodeChat
START OF PREVIOUS DISCUSSION END OF PREVIOUS DISCUSSION
- User
START OF PREVIOUS DISCUSSION END OF PREVIOUS DISCUSSION user: hi, make a python script very simple for fibo numbers
- Assistant
Certainly! Below is a straightforward Python script that outputs Fibonacci numbers up to a specified number of terms. The script calculates the sequence iteratively.
pythondef fibonacci_sequence(n_terms): # Initialize the first two Fibonacci numbers fib_numbers = [0, 1] # Compute the rest of the Fibonacci sequence for i in range(2, n_terms): next_number = fib_numbers[-1] + fib_numbers[-2] fib_numbers.append(next_number) return fib_numbers # Number of terms you want to display n = int(input("Enter the number of terms for the Fibonacci sequence: ")) # Ensure that the entered value is a positive integer if n <= 0: print("Please enter a positive integer.") else: # Get the Fibonacci sequence fibonacci = fibonacci_sequence(n) # Display the computed Fibonacci sequence print(f"Fibonacci sequence with {n} terms: {fibonacci}")