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 python script for fibonacci numbers
- Assistant
Certainly! Below is a simple Python script that generates Fibonacci numbers. The script prompts the user to enter the number of Fibonacci numbers they wish to see and then prints them out.
def fibonacci(n): fibonacci_sequence = [] a, b = 0, 1 for _ in range(n): fibonacci_sequence.append(a) a, b = b, a + b return fibonacci_sequence def main(): num_fibonacci = int(input("How many Fibonacci numbers would you like to generate? ")) if num_fibonacci <= 0: print("Please enter a positive integer.") else: sequence = fibonacci(num_fibonacci) print("The first {} numbers of the Fibonacci sequence are:".format(num_fibonacci)) print(sequence) if __name__ == "__main__": main()To run this script:
- Save the script to a file called
fibonacci.py. - Open a command line or terminal window.
- Run the script by typing
python fibonacci.py(Assuming you've got Python installed and your PATH configured accordingly).
- Save the script to a file called