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 me a python script that prints fibo numbers
- Assistant
Certainly! Below is a simple Python script that prints out the Fibonacci sequence. By default, it prints the first 10 numbers in the sequence, but you can change the value of
nto print more or fewer numbers.def fibonacci(n): fib_sequence = [0, 1] for i in range(2, n): next_number = fib_sequence[-1] + fib_sequence[-2] fib_sequence.append(next_number) return fib_sequence def main(): n = 10 # The number of Fibonacci numbers to print fib_sequence = fibonacci(n) for number in fib_sequence: print(number) if __name__ == "__main__": main()Just copy and paste this script into a Python (.py) file, and run it with Python 3. You can change the variable
nin themain()function to any other positive integer to print that many numbers from the Fibonacci sequence.