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 that prints fibo numbers
- Assistant
Sure! Here is a simple Python script that prints Fibonacci numbers:
pythondef fibo(n): a, b = 0, 1 for _ in range(n): print(a, end=' ') a, b = b, a + b print() # New line at the end of the sequence # The number of Fibonacci numbers to print n = int(input("How many Fibonacci numbers would you like to print? ")) fibo(n)This script defines a function
fibothat prints the firstnFibonacci numbers. Thenvalue is provided by the user's input.You can run this script by copying the code into a file with a
.pyextension (e.g.,fibonacci.py) and then executing this file with Python.Make sure you have Python installed on your system. To execute the file, open your command line (CMD, Terminal, etc.), navigate to the directory where you have saved the Python script, and type:
shellpython fibonacci.pyThen, input the number of Fibonacci numbers you wish to print when prompted.