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: make a short python script that prints fibo numbers
- Assistant
Certainly! Below is a Python script that prints the Fibonacci sequence up to a certain number. This example will print the first 10 numbers in the sequence:
def fibo_sequence(n): fibo_nums = [] a, b = 0, 1 while len(fibo_nums) < n: fibo_nums.append(a) a, b = b, a + b return fibo_nums # Set how many Fibonacci numbers to print how_many = 10 # Get the Fibonacci numbers as a list fibo_numbers = fibo_sequence(how_many) # Print the Fibonacci numbers print(fibo_numbers)When this script is run, it will output:
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]You can change the value of
how_manyto print a different number of Fibonacci numbers.