gpt-4-1106-preview· OpenAI
WildChat-4.8M (AI2)
START OF PREVIOUS DISCUSSION END OF PREVIOUS DISCUSSION
- User
START OF PREVIOUS DISCUSSION END OF PREVIOUS DISCUSSION user: make a pytho,n script to print fibonacci numbers
- Assistant
Certainly! Below is a simple Python script that will print the first n Fibonacci numbers, assuming 'n' is provided by the user input:
# Define a function to generate Fibonacci numbers def fibonacci(n): # Initialize the first two Fibonacci numbers a, b = 0, 1 # Initialize a counter count = 0 # Continue until we've reached the desired number of Fibonacci numbers while count < n: # Print the current Fibonacci number print(a, end=' ') # Update the values of a and b a, b = b, a + b # Increment the counter count += 1 print() # Print a newline character at the end of the sequence # Get the number of Fibonacci numbers to print from user input n = int(input("Enter the number of Fibonacci numbers to generate: ")) # Call our function with the input value fibonacci(n)You can copy this script into a file, say
fibonacci.py, and execute it in your Python environment. It will prompt you for an integer input, which represents the number of Fibonacci numbers you'd like to generate and print to the console.